2 of n.
Change-Id: I5406673e99ed53e4e330ed47f022a17177544daa
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 = '<User comment about action>';
$this->context = RequestContext::newExtraneousContext( $this->title );
# 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
# 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
# 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
*/
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
# 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
$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,
)
);
}
# 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
# 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
# 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
# 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
# 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
* raw edit summary from RecentChange object
* --
*/
-/*
+ /*
function testIrcMsgForBlankingAES() {
// $this->context->msg( 'autosumm-blank', .. );
}
function testIrcMsgForUndoAES() {
// $this->context->msg( 'undo-summary', .. );
}
-
-*/
+ */
/**
* @param $expected String Expected IRC text without colors codes
/* Stubs */
-class ResourceLoaderTestModule extends ResourceLoaderModule { }
+class ResourceLoaderTestModule extends ResourceLoaderModule {}
/* Hooks */
global $wgHooks;
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() {
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
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 );
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;
}
#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 );
}
$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' );
}
}
*/
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
) );
}
$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() );
$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() );
$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() );
$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() );
$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() );
}
$revisions[4]->insertOn( $dbw );
// test it ---------------------------------
- $since = $revisions[ $sinceIdx ]->getTimestamp();
+ $since = $revisions[$sinceIdx]->getTimestamp();
$wasLast = Revision::userWasLastToEdit( $dbw, $page->getId(), $userA->getId(), $since );
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' );
}
/**
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" );
// 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" );
$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,
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" ),
);
}
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" ),
);
}
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' ),
);
}
//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' ) ),
);
}
//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 ),
);
}
}
- public function dataGetSize( ) {
+ public function dataGetSize() {
return array(
array( "hello world.", CONTENT_MODEL_WIKITEXT, 12 ),
array( serialize( "hello world." ), "testing", 12 ),
$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." ) ) ),
$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' );
$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' );
*
* @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,
)
);
parent::__construct( $text, "RevisionTestModifyableContent" );
}
- public function copy( ) {
+ public function copy() {
return new RevisionTestModifyableContent( $this->mText );
}
class RevisionTestModifyableContentHandler extends TextContentHandler {
- public function __construct( ) {
+ public function __construct() {
parent::__construct( "RevisionTestModifyableContent", array( CONTENT_FORMAT_TEXT ) );
}
* 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" );
}
/**
* @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;
}
# Enable HTML5 mode
'wgHtml5' => true,
'wgUseTidy' => false
- ));
+ ) );
- if( $escaped ) {
+ if ( $escaped ) {
$this->assertEquals( "<$tag>",
Sanitizer::removeHTMLtags( "<$tag>" )
);
* 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 ),
function testSelfClosingTag() {
$this->setMwGlobals( array(
'wgUseTidy' => false
- ));
+ ) );
$this->assertEquals(
'<div>Hello world</div>',
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);' ),
);
}
}
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 );
}
$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" );
$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' );
}
/**
* String containing the a sample selenium settings
*/
- private $testConfig0 =
-'
+ private $testConfig0 = '
[SeleniumSettings]
browsers[firefox] = "*firefox"
browsers[iexplorer] = "*iexploreproxy"
/**
* 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,
* 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"
* 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,
$seleniumBrowsers = array();
$seleniumTestSuites = array();
- SeleniumConfig::getSeleniumSettings($seleniumSettings,
+ SeleniumConfig::getSeleniumSettings( $seleniumSettings,
$seleniumBrowsers,
$seleniumTestSuites,
"Some_fake_settings_file.ini" );
-
}
/**
$seleniumTestSuites = array();
global $wgSeleniumConfigFile;
$wgSeleniumConfigFile = '';
- SeleniumConfig::getSeleniumSettings($seleniumSettings,
+ SeleniumConfig::getSeleniumSettings( $seleniumSettings,
$seleniumBrowsers,
- $seleniumTestSuites);
+ $seleniumTestSuites );
}
/**
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'
);
}
* @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 )
);
}
-
-
}
* @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,
* @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'
*/
function escaped( $string ) {
$escaped = '';
- for($i=0; $i<strlen($string);$i++) {
+ for ( $i = 0; $i < strlen( $string ); $i++ ) {
$char = $string[$i];
- $val = ord($char);
- if( $val > 127 ) {
- $escaped .='\x' . dechex($val);
+ $val = ord( $char );
+ if ( $val > 127 ) {
+ $escaped .= '\x' . dechex( $val );
} else {
$escaped .= $char;
}
# 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 ),
);
'wgLang' => Language::factory( 'en' ),
) );
}
+
/**
* Test parsing of valid timestamps and outputing to MW format.
* @dataProvider provideValidTimestamps
$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" );
$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" );
$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" );
$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' ) ),
$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 );
$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 );
$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 );
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;
$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() {
$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(
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() {
$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() {
$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 ) );
}
$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 ) );
}
# $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
$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 )
* ^--- needed for language cache stuff
*/
class TitleTest extends MediaWikiTestCase {
-
protected function setUp() {
parent::setUp();
array( 'Special:Version/param', 'param' ),
);
}
-
+
/**
* Auth-less test of Title::isValidMoveOperation
- *
+ *
* @group Database
* @param string $source
* @param string $target
}
}
}
-
+
/**
* Provides test parameter values for testIsValidMoveOperation()
*/
* @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 );
}
$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;
$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 );
* Provides test parameter values for testWgWhitelistReadRegexp()
*/
function dataWgWhitelistReadRegexp() {
- $ALLOWED = true;
+ $ALLOWED = true;
$DISALLOWED = false;
return array(
}
return $result;
}
-
+
public static function provideTestIsValidMoveOperation() {
- return array(
+ return array(
array( 'Test', 'Test', 'selfmove' ),
array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
);
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' ),
);
}
/**
* @dataProvider provideBaseTitleCases
*/
- function testExtractingBaseTextFromTitle( $title, $expected, $msg='' ) {
+ function testExtractingBaseTextFromTitle( $title, $expected, $msg = '' ) {
$title = Title::newFromText( $title );
$this->assertEquals( $expected,
$title->getBaseText(),
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(),
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' ),
);
}
* @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(),
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' ),
);
}
-
}
* @group Database
*/
class UserTest extends MediaWikiTestCase {
-
/**
* @var User
*/
$this->assertContains( 'modifytest', $rights );
$this->assertNotContains( 'nukeworld', $rights );
}
+
public function testRevokePermissions() {
$rights = User::getGroupPermissions( array( 'unittesters', 'formertesters' ) );
$this->assertNotContains( 'runtest', $rights );
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' ),
);
}
// 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 );
}
/**
* @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 );
}
}