3 of n.
Change-Id: I62ad009018c54da6cf081c334e44eb98a3c72695
<?php
/**
-* @group ContentHandler
-* @group Database
-* ^--- important, causes temporary tables to be used instead of the real database
-* @group medium
-**/
+ * @group ContentHandler
+ * @group Database
+ * ^--- important, causes temporary tables to be used instead of the real database
+ * @group medium
+ **/
class WikiPageTest extends MediaWikiLangTestCase {
function __construct( $name = null, array $data = array(), $dataName = '' ) {
parent::__construct( $name, $data, $dataName );
- $this->tablesUsed = array_merge (
+ $this->tablesUsed = array_merge(
$this->tablesUsed,
array( 'page',
- 'revision',
- 'text',
+ 'revision',
+ 'text',
- 'recentchanges',
- 'logging',
+ 'recentchanges',
+ 'logging',
- 'page_props',
- 'pagelinks',
- 'categorylinks',
- 'langlinks',
- 'externallinks',
- 'imagelinks',
- 'templatelinks',
- 'iwlinks' ) );
+ 'page_props',
+ 'pagelinks',
+ 'categorylinks',
+ 'langlinks',
+ 'externallinks',
+ 'imagelinks',
+ 'templatelinks',
+ 'iwlinks' ) );
}
protected function setUp() {
return $p;
}
-
/**
* @param String|Title|WikiPage $page
* @param String $text
$title = $page->getTitle();
$content = ContentHandler::makeContent( "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
- . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
- $title, CONTENT_MODEL_WIKITEXT );
+ . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+ $title, CONTENT_MODEL_WIKITEXT );
$page->doEditContent( $content, "[[testing]] 1" );
# ------------------------
$content = ContentHandler::makeContent( "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
- . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.",
- $title, CONTENT_MODEL_WIKITEXT );
+ . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.",
+ $title, CONTENT_MODEL_WIKITEXT );
$page->doEditContent( $content, "testing 2" );
$page = $this->newPage( $title );
$text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
- . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
+ . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
$page->doEdit( $text, "[[testing]] 1" );
# ------------------------
$text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
- . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.";
+ . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.";
$page->doEdit( $text, "testing 2" );
// any
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '',
- 'any',
- true
+ CONTENT_MODEL_WIKITEXT,
+ '',
+ 'any',
+ true
),
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'any',
- true
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'any',
+ true
),
// comma
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'comma',
- false
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'comma',
+ false
),
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo, bar',
- 'comma',
- true
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo, bar',
+ 'comma',
+ true
),
// link
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'link',
- false
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'link',
+ false
),
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo [[bar]]',
- 'link',
- true
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo [[bar]]',
+ 'link',
+ true
),
// redirects
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '#REDIRECT [[bar]]',
- 'any',
- false
+ CONTENT_MODEL_WIKITEXT,
+ '#REDIRECT [[bar]]',
+ 'any',
+ false
),
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '#REDIRECT [[bar]]',
- 'comma',
- false
+ CONTENT_MODEL_WIKITEXT,
+ '#REDIRECT [[bar]]',
+ 'comma',
+ false
),
array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '#REDIRECT [[bar]]',
- 'link',
- false
+ CONTENT_MODEL_WIKITEXT,
+ '#REDIRECT [[bar]]',
+ 'link',
+ false
),
// not a content namespace
array( 'Talk:WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'any',
- false
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'any',
+ false
),
array( 'Talk:WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo, bar',
- 'comma',
- false
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo, bar',
+ 'comma',
+ false
),
array( 'Talk:WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo [[bar]]',
- 'link',
- false
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo [[bar]]',
+ 'link',
+ false
),
// not a content namespace, different model
array( 'MediaWiki:WikiPageTest_testIsCountable.js',
- null,
- 'Foo',
- 'any',
- false
+ null,
+ 'Foo',
+ 'any',
+ false
),
array( 'MediaWiki:WikiPageTest_testIsCountable.js',
- null,
- 'Foo, bar',
- 'comma',
- false
+ null,
+ 'Foo, bar',
+ 'comma',
+ false
),
array( 'MediaWiki:WikiPageTest_testIsCountable.js',
- null,
- 'Foo [[bar]]',
- 'link',
- false
+ null,
+ 'Foo [[bar]]',
+ 'link',
+ false
),
);
}
$page = $this->createPage( $title, $text, $model );
$hasLinks = wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1,
- array( 'pl_from' => $page->getId() ), __METHOD__ );
+ array( 'pl_from' => $page->getId() ), __METHOD__ );
$editInfo = $page->prepareContentForEdit( $page->getContent() );
$w = $page->isCountable( $editInfo );
$this->assertEquals( $expected, $v, "isCountable( null ) returned unexpected value " . var_export( $v, true )
- . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
+ . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
$this->assertEquals( $expected, $w, "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
- . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
+ . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
}
public static function provideGetParserOutput() {
return array(
- array( CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i></p>"),
+ array( CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i></p>" ),
// @todo: more...?
);
}
return $po;
}
- public function testGetParserOutput_nonexisting( ) {
+ public function testGetParserOutput_nonexisting() {
static $count = 0;
- $count ++;
+ $count++;
$page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
$this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
}
- public function testGetParserOutput_badrev( ) {
+ public function testGetParserOutput_badrev() {
$page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT );
$opt = new ParserOptions();
//NOTE: assume the Help namespace to contain wikitext
return array(
array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "0",
- "No more",
- null,
- trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest::$sections ) )
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "0",
+ "No more",
+ null,
+ trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest::$sections ) )
),
array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "",
- "No more",
- null,
- "No more"
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "",
+ "No more",
+ null,
+ "No more"
),
array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "2",
- "== TEST ==\nmore fun",
- null,
- trim( preg_replace( '/^== test ==.*== foo ==/sm',
- "== TEST ==\nmore fun\n\n== foo ==",
- WikiPageTest::$sections ) )
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "2",
+ "== TEST ==\nmore fun",
+ null,
+ trim( preg_replace( '/^== test ==.*== foo ==/sm',
+ "== TEST ==\nmore fun\n\n== foo ==",
+ WikiPageTest::$sections ) )
),
array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "8",
- "No more",
- null,
- trim( WikiPageTest::$sections )
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "8",
+ "No more",
+ null,
+ trim( WikiPageTest::$sections )
),
array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "new",
- "No more",
- "New",
- trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more"
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "new",
+ "No more",
+ "New",
+ trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more"
),
);
}
/* @todo FIXME: fix this!
public function testGetUndoText() {
- $this->checkHasDiff3();
+ $this->checkHasDiff3();
- $text = "one";
- $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
- $rev1 = $page->getRevision();
+ $text = "one";
+ $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
+ $rev1 = $page->getRevision();
- $text .= "\n\ntwo";
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section two");
- $rev2 = $page->getRevision();
+ $text .= "\n\ntwo";
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section two");
+ $rev2 = $page->getRevision();
- $text .= "\n\nthree";
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section three");
- $rev3 = $page->getRevision();
+ $text .= "\n\nthree";
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section three");
+ $rev3 = $page->getRevision();
- $text .= "\n\nfour";
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section four");
- $rev4 = $page->getRevision();
+ $text .= "\n\nfour";
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section four");
+ $rev4 = $page->getRevision();
- $text .= "\n\nfive";
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section five");
- $rev5 = $page->getRevision();
+ $text .= "\n\nfive";
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section five");
+ $rev5 = $page->getRevision();
- $text .= "\n\nsix";
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section six");
- $rev6 = $page->getRevision();
+ $text .= "\n\nsix";
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section six");
+ $rev6 = $page->getRevision();
- $undo6 = $page->getUndoText( $rev6 );
- if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
- $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
+ $undo6 = $page->getUndoText( $rev6 );
+ if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
+ $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
- $undo3 = $page->getUndoText( $rev4, $rev2 );
- if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
- $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
+ $undo3 = $page->getUndoText( $rev4, $rev2 );
+ if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
+ $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
- $undo2 = $page->getUndoText( $rev2 );
- if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
- $this->assertEquals( "one\n\nfive", $undo2 );
+ $undo2 = $page->getUndoText( $rev2 );
+ if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
+ $this->assertEquals( "one\n\nfive", $undo2 );
}
- */
+ */
/**
* @todo FIXME: this is a better rollback test than the one below, but it keeps failing in jenkins for some reason.
*/
public function broken_testDoRollback() {
$admin = new User();
- $admin->setName("Admin");
+ $admin->setName( "Admin" );
$text = "one";
$page = $this->newPage( "WikiPageTest_testDoRollback" );
$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
- "section one", EDIT_NEW, false, $admin );
+ "section one", EDIT_NEW, false, $admin );
$user1 = new User();
$user1->setName( "127.0.1.11" );
$text .= "\n\ntwo";
$page = new WikiPage( $page->getTitle() );
$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section two", 0, false, $user1 );
+ "adding section two", 0, false, $user1 );
$user2 = new User();
$user2->setName( "127.0.2.13" );
$text .= "\n\nthree";
$page = new WikiPage( $page->getTitle() );
$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section three", 0, false, $user2 );
+ "adding section three", 0, false, $user2 );
# we are having issues with doRollback spuriously failing. apparently the last revision somehow goes missing
# or not committed under some circumstances. so, make sure the last revision has the right user name.
$page = new WikiPage( $page->getTitle() );
$this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
- "rollback did not revert to the correct revision" );
+ "rollback did not revert to the correct revision" );
$this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
}
*/
public function testDoRollback() {
$admin = new User();
- $admin->setName("Admin");
+ $admin->setName( "Admin" );
$text = "one";
$page = $this->newPage( "WikiPageTest_testDoRollback" );
$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- "section one", EDIT_NEW, false, $admin );
+ "section one", EDIT_NEW, false, $admin );
$rev1 = $page->getRevision();
$user1 = new User();
$text .= "\n\ntwo";
$page = new WikiPage( $page->getTitle() );
$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- "adding section two", 0, false, $user1 );
+ "adding section two", 0, false, $user1 );
# now, try the rollback
$admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
$page = new WikiPage( $page->getTitle() );
$this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
- "rollback did not revert to the correct revision" );
+ "rollback did not revert to the correct revision" );
$this->assertEquals( "one", $page->getContent()->getNativeData() );
}
- public static function provideGetAutosummary( ) {
+ public static function provideGetAutosummary() {
return array(
array(
'Hello there, world!',
$summary = $page->getAutosummary( $old, $new, $flags );
$this->assertTrue( (bool)preg_match( $expected, $summary ),
- "Autosummary didn't match expected pattern $expected: $summary" );
+ "Autosummary didn't match expected pattern $expected: $summary" );
}
- public static function provideGetAutoDeleteReason( ) {
+ public static function provideGetAutoDeleteReason() {
return array(
array(
array(),
array(
array(
array( "first edit: "
- . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
- . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. "
- . "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea "
- . "takimata sanctus est Lorem ipsum dolor sit amet.'", null ),
+ . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
+ . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. "
+ . "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea "
+ . "takimata sanctus est Lorem ipsum dolor sit amet.'", null ),
),
'/first edit:.*\.\.\."/',
false
foreach ( $edits as $edit ) {
$user = new User();
- if ( !empty( $edit[1] ) ) $user->setName( $edit[1] );
- else $user = $wgUser;
+ if ( !empty( $edit[1] ) ) {
+ $user->setName( $edit[1] );
+ } else {
+ $user = $wgUser;
+ }
$content = ContentHandler::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
$reason = $page->getAutoDeleteReason( $hasHistory );
- if ( is_bool( $expectedResult ) || is_null( $expectedResult ) ) $this->assertEquals( $expectedResult, $reason );
- else $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
- "Autosummary didn't match expected pattern $expectedResult: $reason" );
+ if ( is_bool( $expectedResult ) || is_null( $expectedResult ) ) {
+ $this->assertEquals( $expectedResult, $reason );
+ } else {
+ $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
+ "Autosummary didn't match expected pattern $expectedResult: $reason" );
+ }
$this->assertEquals( $expectedHistory, $hasHistory,
- "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
+ "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
$page->doDeleteArticle( "done" );
}
public static function providePreSaveTransform() {
return array(
array( 'hello this is ~~~',
- "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
+ "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
),
array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
- 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
),
);
}
public function testPreSaveTransform( $text, $expected ) {
$this->hideDeprecated( 'WikiPage::preSaveTransform' );
$user = new User();
- $user->setName("127.0.0.1");
+ $user->setName( "127.0.0.1" );
//NOTE: assume Help namespace to contain wikitext
$page = $this->newPage( "Help:WikiPageTest_testPreloadTransform" );
$this->setMwGlobals( array(
'wgHtml5' => true,
'wgWellFormedXml' => true,
- ));
+ ) );
$this->select = new XmlSelect();
}
+
protected function tearDown() {
parent::tearDown();
$this->select = null;
* See http://en.wikipedia.org/wiki/Gray_code
*/
# $name $id $default
- array( false , false, false, '<select></select>' ),
- array( false , false, 'foo', '<select></select>' ),
- array( false , 'id' , 'foo', '<select id="id"></select>' ),
- array( false , 'id' , false, '<select id="id"></select>' ),
- array( 'name', 'id' , false, '<select name="name" id="id"></select>' ),
- array( 'name', 'id' , 'foo', '<select name="name" id="id"></select>' ),
- array( 'name', false, 'foo', '<select name="name"></select>' ),
- array( 'name', false, false, '<select name="name"></select>' ),
+ array( false, false, false, '<select></select>' ),
+ array( false, false, 'foo', '<select></select>' ),
+ array( false, 'id', 'foo', '<select id="id"></select>' ),
+ array( false, 'id', false, '<select id="id"></select>' ),
+ array( 'name', 'id', false, '<select name="name" id="id"></select>' ),
+ array( 'name', 'id', 'foo', '<select name="name" id="id"></select>' ),
+ array( 'name', false, 'foo', '<select name="name"></select>' ),
+ array( 'name', false, false, '<select name="name"></select>' ),
);
}
$this->select->addOption( 'foo' );
$this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
}
+
public function testAddOptionWithDefault() {
$this->select->addOption( 'foo', true );
$this->assertEquals( '<select><option value="1">foo</option></select>', $this->select->getHTML() );
}
+
public function testAddOptionWithFalse() {
$this->select->addOption( 'foo', false );
$this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
}
+
public function testAddOptionWithValueZero() {
$this->select->addOption( 'foo', 0 );
$this->assertEquals( '<select><option value="0">foo</option></select>', $this->select->getHTML() );
}
+
# End XmlSelect::addOption() similar to Xml::option
public function testSetDefault() {
$this->select->addOption( 'bar1' );
$this->select->addOption( 'foo2' );
$this->assertEquals(
-'<select><option value="foo1">foo1</option>' . "\n" .
-'<option value="bar1" selected="">bar1</option>' . "\n" .
-'<option value="foo2">foo2</option></select>', $this->select->getHTML() );
+ '<select><option value="foo1">foo1</option>' . "\n" .
+ '<option value="bar1" selected="">bar1</option>' . "\n" .
+ '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
}
/**
$this->select->addOption( 'foo2' );
$this->select->setDefault( 'bar1' ); # setting default after adding options
$this->assertEquals(
-'<select><option value="foo1">foo1</option>' . "\n" .
-'<option value="bar1" selected="">bar1</option>' . "\n" .
-'<option value="foo2">foo2</option></select>', $this->select->getHTML() );
+ '<select><option value="foo1">foo1</option>' . "\n" .
+ '<option value="bar1" selected="">bar1</option>' . "\n" .
+ '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
}
public function testGetAttributes() {
# verify string / integer
$this->assertEquals(
$this->select->getAttribute( '1911' ),
- 'razor'
+ 'razor'
);
$this->assertEquals(
$this->select->getAttribute( 'dummy' ),
$langObj->setNamespaces( array(
-2 => 'Media',
-1 => 'Special',
- 0 => '',
- 1 => 'Talk',
- 2 => 'User',
- 3 => 'User_talk',
- 4 => 'MyWiki',
- 5 => 'MyWiki_Talk',
- 6 => 'File',
- 7 => 'File_talk',
- 8 => 'MediaWiki',
- 9 => 'MediaWiki_talk',
- 10 => 'Template',
- 11 => 'Template_talk',
- 100 => 'Custom',
- 101 => 'Custom_talk',
+ 0 => '',
+ 1 => 'Talk',
+ 2 => 'User',
+ 3 => 'User_talk',
+ 4 => 'MyWiki',
+ 5 => 'MyWiki_Talk',
+ 6 => 'File',
+ 7 => 'File_talk',
+ 8 => 'MediaWiki',
+ 9 => 'MediaWiki_talk',
+ 10 => 'Template',
+ 11 => 'Template_talk',
+ 100 => 'Custom',
+ 101 => 'Custom_talk',
) );
$this->setMwGlobals( array(
}
public function testExpandAttributes() {
- $this->assertNull( Xml::expandAttributes(null),
+ $this->assertNull( Xml::expandAttributes( null ),
'Converting a null list of attributes'
);
$this->assertEquals( '', Xml::expandAttributes( array() ),
}
public function testExpandAttributesException() {
- $this->setExpectedException('MWException');
- Xml::expandAttributes('string');
+ $this->setExpectedException( 'MWException' );
+ Xml::expandAttributes( 'string' );
}
function testElementOpen() {
'Input with a value of 0 (bug 23797)'
);
}
+
function testElementEscaping() {
$this->assertEquals(
'<element>hello <there> you & you</element>',
$this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
}
- public function testDateMenu( ) {
- $curYear = intval(gmdate('Y'));
- $prevYear = $curYear - 1;
+ public function testDateMenu() {
+ $curYear = intval( gmdate( 'Y' ) );
+ $prevYear = $curYear - 1;
- $curMonth = intval(gmdate('n'));
+ $curMonth = intval( gmdate( 'n' ) );
$prevMonth = $curMonth - 1;
- if( $prevMonth == 0 ) { $prevMonth = 12; }
+ if ( $prevMonth == 0 ) {
+ $prevMonth = 12;
+ }
$nextMonth = $curMonth + 1;
- if( $nextMonth == 13 ) { $nextMonth = 1; }
+ if ( $nextMonth == 13 ) {
+ $nextMonth = 1;
+ }
$this->assertEquals(
'<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
-'<option value="1">January</option>' . "\n" .
-'<option value="2" selected="">February</option>' . "\n" .
-'<option value="3">March</option>' . "\n" .
-'<option value="4">April</option>' . "\n" .
-'<option value="5">May</option>' . "\n" .
-'<option value="6">June</option>' . "\n" .
-'<option value="7">July</option>' . "\n" .
-'<option value="8">August</option>' . "\n" .
-'<option value="9">September</option>' . "\n" .
-'<option value="10">October</option>' . "\n" .
-'<option value="11">November</option>' . "\n" .
-'<option value="12">December</option></select>',
+ '<option value="1">January</option>' . "\n" .
+ '<option value="2" selected="">February</option>' . "\n" .
+ '<option value="3">March</option>' . "\n" .
+ '<option value="4">April</option>' . "\n" .
+ '<option value="5">May</option>' . "\n" .
+ '<option value="6">June</option>' . "\n" .
+ '<option value="7">July</option>' . "\n" .
+ '<option value="8">August</option>' . "\n" .
+ '<option value="9">September</option>' . "\n" .
+ '<option value="10">October</option>' . "\n" .
+ '<option value="11">November</option>' . "\n" .
+ '<option value="12">December</option></select>',
Xml::dateMenu( 2011, 02 ),
"Date menu for february 2011"
);
$this->assertEquals(
'<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
-'<option value="1">January</option>' . "\n" .
-'<option value="2">February</option>' . "\n" .
-'<option value="3">March</option>' . "\n" .
-'<option value="4">April</option>' . "\n" .
-'<option value="5">May</option>' . "\n" .
-'<option value="6">June</option>' . "\n" .
-'<option value="7">July</option>' . "\n" .
-'<option value="8">August</option>' . "\n" .
-'<option value="9">September</option>' . "\n" .
-'<option value="10">October</option>' . "\n" .
-'<option value="11">November</option>' . "\n" .
-'<option value="12">December</option></select>',
- Xml::dateMenu( 2011, -1),
+ '<option value="1">January</option>' . "\n" .
+ '<option value="2">February</option>' . "\n" .
+ '<option value="3">March</option>' . "\n" .
+ '<option value="4">April</option>' . "\n" .
+ '<option value="5">May</option>' . "\n" .
+ '<option value="6">June</option>' . "\n" .
+ '<option value="7">July</option>' . "\n" .
+ '<option value="8">August</option>' . "\n" .
+ '<option value="9">September</option>' . "\n" .
+ '<option value="10">October</option>' . "\n" .
+ '<option value="11">November</option>' . "\n" .
+ '<option value="12">December</option></select>',
+ Xml::dateMenu( 2011, -1 ),
"Date menu with negative month for 'All'"
);
$this->assertEquals(
Xml::dateMenu( $curYear, $curMonth ),
- Xml::dateMenu( '' , $curMonth ),
+ Xml::dateMenu( '', $curMonth ),
"Date menu year is the current one when not specified"
);
$this->assertEquals(
'<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
-'<option value="1">January</option>' . "\n" .
-'<option value="2">February</option>' . "\n" .
-'<option value="3">March</option>' . "\n" .
-'<option value="4">April</option>' . "\n" .
-'<option value="5">May</option>' . "\n" .
-'<option value="6">June</option>' . "\n" .
-'<option value="7">July</option>' . "\n" .
-'<option value="8">August</option>' . "\n" .
-'<option value="9">September</option>' . "\n" .
-'<option value="10">October</option>' . "\n" .
-'<option value="11">November</option>' . "\n" .
-'<option value="12">December</option></select>',
+ '<option value="1">January</option>' . "\n" .
+ '<option value="2">February</option>' . "\n" .
+ '<option value="3">March</option>' . "\n" .
+ '<option value="4">April</option>' . "\n" .
+ '<option value="5">May</option>' . "\n" .
+ '<option value="6">June</option>' . "\n" .
+ '<option value="7">July</option>' . "\n" .
+ '<option value="8">August</option>' . "\n" .
+ '<option value="9">September</option>' . "\n" .
+ '<option value="10">October</option>' . "\n" .
+ '<option value="11">November</option>' . "\n" .
+ '<option value="12">December</option></select>',
Xml::dateMenu( '', '' ),
"Date menu with neither year or month"
);
'label() with no attribs'
);
}
+
function testLabelAttributeCanOnlyBeClassOrTitle() {
$this->assertEquals(
'<label for="id">name</label>',
$this->assertEquals(
'<label for="id" class="nice" title="nice tooltip">name</label>',
Xml::label( 'name', 'id', array(
- 'generated' => true,
- 'class' => 'nice',
- 'title' => 'nice tooltip',
- 'anotherattr' => 'value',
+ 'generated' => true,
+ 'class' => 'nice',
+ 'title' => 'nice tooltip',
+ 'anotherattr' => 'value',
)
),
'label() skip all attributes but "class" and "title"'
}
function testMultiDisk0() {
- $this->readZipAssertError( 'split.zip', 'zip-unsupported',
+ $this->readZipAssertError( 'split.zip', 'zip-unsupported',
'Split zip error' );
}
function testNoSignature() {
- $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
+ $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
'No signature should give "wrong format" error' );
}
}
function testWrongCDStart() {
- $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
+ $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
'Wrong CD start disk error' );
}
*/
function testInvalidEmail() {
global $wgEnableEmail;
- if( !$wgEnableEmail ) {
+ if ( !$wgEnableEmail ) {
$this->markTestSkipped( 'email is not enabled, so createaccount does not check it' );
}
$this->doApiRequest( array(
$this->markTestIncomplete( "The user UTApiBlockee does not exist" );
}
- if( !isset( $data[0]['query']['pages'] ) ) {
+ if ( !isset( $data[0]['query']['pages'] ) ) {
$this->markTestIncomplete( "No block token found" );
}
'reason' => 'Some reason',
'token' => $pageinfo['blocktoken'] ), null, false, self::$users['sysop']->user );
- $block = Block::newFromTarget('UTApiBlockee');
+ $block = Block::newFromTarget( 'UTApiBlockee' );
$this->assertTrue( !is_null( $block ), 'Block is valid' );
'action' => $action,
'user' => 'UTApiBlockee',
'reason' => 'Some reason',
- ),
+ ),
null,
false,
self::$users['sysop']->user
*/
function provideBlockUnblockAction() {
return array(
- array( 'block' ),
+ array( 'block' ),
array( 'unblock' ),
);
}
parent::teardown();
}
- function testEdit( ) {
+ function testEdit() {
$name = 'Help:ApiEditPageTest_testEdit'; // assume Help namespace to default to wikitext
// -- test new page --------------------------------------------
$apiResult = $this->doApiRequestWithToken( array(
- 'action' => 'edit',
- 'title' => $name,
- 'text' => 'some text', ) );
+ 'action' => 'edit',
+ 'title' => $name,
+ 'text' => 'some text',
+ ) );
$apiResult = $apiResult[0];
// Validate API result data
// -- test existing page, no change ----------------------------
$data = $this->doApiRequestWithToken( array(
- 'action' => 'edit',
- 'title' => $name,
- 'text' => 'some text', ) );
+ 'action' => 'edit',
+ 'title' => $name,
+ 'text' => 'some text',
+ ) );
$this->assertEquals( 'Success', $data[0]['edit']['result'] );
// -- test existing page, with change --------------------------
$data = $this->doApiRequestWithToken( array(
- 'action' => 'edit',
- 'title' => $name,
- 'text' => 'different text' ) );
+ 'action' => 'edit',
+ 'title' => $name,
+ 'text' => 'different text'
+ ) );
$this->assertEquals( 'Success', $data[0]['edit']['result'] );
);
}
- function testNonTextEdit( ) {
+ function testNonTextEdit() {
$name = 'Dummy:ApiEditPageTest_testNonTextEdit';
$data = serialize( 'some bla bla text' );
if ( $text !== null ) {
if ( $text === '' ) {
// can't create an empty page, so create it with some content
- list( $re,, ) = $this->doApiRequestWithToken( array(
+ list( $re, , ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => '(dummy)', ) );
}
- list( $re,, ) = $this->doApiRequestWithToken( array(
+ list( $re, , ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => $text, ) );
}
// -- try append/prepend --------------------------------------------
- list( $re,, ) = $this->doApiRequestWithToken( array(
+ list( $re, , ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
$op . 'text' => $append, ) );
// try to save edit, expect conflict
try {
- list( $re,, ) = $this->doApiRequestWithToken( array(
+ list( $re, , ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => 'nix bar!',
'basetimestamp' => $baseTime,
- ), null, self::$users['sysop']->user );
+ ), null, self::$users['sysop']->user );
$this->fail( 'edit conflict expected' );
} catch ( UsageException $ex ) {
$this->forceRevisionDate( $rpage, '20120101020202' );
// try to save edit; should work, because we follow the redirect
- list( $re,, ) = $this->doApiRequestWithToken( array(
+ list( $re, , ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $rname,
'text' => 'nix bar!',
// try again, without following the redirect. Should fail.
try {
- list( $re,, ) = $this->doApiRequestWithToken( array(
+ list( $re, , ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $rname,
'text' => 'nix bar!',
$this->forceRevisionDate( $rpage, '20120101020202' );
// try to save edit; should work, following the redirect.
- list( $re,, ) = $this->doApiRequestWithToken( array(
+ list( $re, , ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $rname,
'text' => 'nix bar!',
) {
$generators = $this->getApiQuery()->getGenerators();
$this->assertArrayHasKey( $moduleName, $generators,
- "API module '$moduleName' of class '$moduleClass' (an ApiQueryGeneratorBase subclass) must be listed in ApiQuery::\$mQueryGenerators or added to \$wgAPIGeneratorModules."
+ "API module '$moduleName' of class '$moduleClass' (an ApiQueryGeneratorBase subclass) must be listed in ApiQuery::\$mQueryGenerators or added to \$wgAPIGeneratorModules."
);
}
/**
* Returns API modules which are subclassing ApiQueryGeneratorBase.
* Case format is:
- * (moduleName, moduleClass)
+ * (moduleName, moduleClass)
*/
public function provideApiquerygeneratorbaseChilds() {
$cases = array();
$modules = $this->getApiQuery()->getModuleManager()->getNamesWithClasses();
- foreach( $modules as $moduleName => $moduleClass ) {
- if( !is_subclass_of( $moduleClass, 'ApiQueryGeneratorBase' ) ) {
+ foreach ( $modules as $moduleName => $moduleClass ) {
+ if ( !is_subclass_of( $moduleClass, 'ApiQueryGeneratorBase' ) ) {
continue;
}
$cases[] = array( $moduleName, $moduleClass );
public function provideListedApiqueryGenerators() {
$cases = array();
$generators = $this->getApiQuery()->getGenerators();
- foreach( $generators as $generatorName => $generatorClass ) {
+ foreach ( $generators as $generatorName => $generatorClass ) {
$cases[] = array( $generatorName, $generatorClass );
}
return $cases;
'page' => $somePage ) );
$this->fail( "API did not return an error when parsing a nonexistent page" );
- } catch(UsageException $ex){
+ } catch ( UsageException $ex ) {
$this->assertEquals( 'missingtitle', $ex->getCodeString(),
"Parse request for nonexistent page must give 'missingtitle' error: " . var_export( $ex->getMessageArray(), true ) );
}
"Purge request for three articles should give back three results received: " . var_export( $data[0]['purge'], true ) );
$pages = array( 'UTPage' => 'purged', $somePage => 'missing', '%5D' => 'invalid' );
- foreach( $data[0]['purge'] as $v ) {
+ foreach ( $data[0]['purge'] as $v ) {
$this->assertArrayHasKey( $pages[$v['title']], $v );
}
}
$this->assertEquals(
null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
- "enablechunks" => false ), "filename", "enablechunks" ) );
+ "enablechunks" => false ), "filename", "enablechunks" ) );
}
/**
$this->assertEquals(
null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
- "enablechunks" => 0 ), "filename", "enablechunks" ) );
+ "enablechunks" => 0 ), "filename", "enablechunks" ) );
}
/**
$this->assertEquals(
null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
- "enablechunks" => true ), "filename", "enablechunks" ) );
+ "enablechunks" => true ), "filename", "enablechunks" ) );
}
/**
$token = $result["login"]["token"];
- $ret = $this->doApiRequest( array(
- "action" => "login",
- "lgtoken" => $token,
- "lgname" => $user->username,
- "lgpassword" => "badnowayinhell",
- ), $ret[2]
+ $ret = $this->doApiRequest(
+ array(
+ "action" => "login",
+ "lgtoken" => $token,
+ "lgname" => $user->username,
+ "lgpassword" => "badnowayinhell",
+ ),
+ $ret[2]
);
$result = $ret[0];
$user->user->logOut();
$ret = $this->doApiRequest( array(
- "action" => "login",
- "lgname" => $user->username,
- "lgpassword" => $user->password,
+ "action" => "login",
+ "lgname" => $user->username,
+ "lgpassword" => $user->password,
)
);
$this->assertEquals( "NeedToken", $a );
$token = $result["login"]["token"];
- $ret = $this->doApiRequest( array(
- "action" => "login",
- "lgtoken" => $token,
- "lgname" => $user->username,
- "lgpassword" => $user->password,
- ), $ret[2]
+ $ret = $this->doApiRequest(
+ array(
+ "action" => "login",
+ "lgtoken" => $token,
+ "lgname" => $user->username,
+ "lgpassword" => $user->password,
+ ),
+ $ret[2]
);
$result = $ret[0];
* @group Broken
*/
function testApiGotCookie() {
- $this->markTestIncomplete( "The server can't do external HTTP requests, and the internal one won't give cookies" );
+ $this->markTestIncomplete( "The server can't do external HTTP requests, and the internal one won't give cookies" );
global $wgServer, $wgScriptPath;
$req = MWHttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
array( "method" => "POST",
"postData" => array(
- "lgname" => $user->username,
- "lgpassword" => $user->password ) ) );
+ "lgname" => $user->username,
+ "lgpassword" => $user->password
+ )
+ )
+ );
$req->execute();
libxml_use_internal_errors( true );
-<?php
+<?php
abstract class ApiTestCase extends MediaWikiLangTestCase {
protected static $apiUrl;
$token = $data[0]['login']['token'];
- $data = $this->doApiRequest( array(
- 'action' => 'login',
- 'lgtoken' => $token,
- 'lgname' => self::$users['sysop']->username,
- 'lgpassword' => self::$users['sysop']->password
- ), $data[2] );
+ $data = $this->doApiRequest(
+ array(
+ 'action' => 'login',
+ 'lgtoken' => $token,
+ 'lgname' => self::$users['sysop']->username,
+ 'lgpassword' => self::$users['sysop']->password,
+ ),
+ $data[2]
+ );
return $data;
}
}
class MockApi extends ApiBase {
- public function execute() { }
- public function getVersion() { }
+ public function execute() {}
+
+ public function getVersion() {}
- public function __construct() { }
+ public function __construct() {}
public function getAllowedParams() {
return array(
// see if it now doesn't exist; reload
$title = Title::newFromText( $title->getText(), NS_FILE );
}
- return ! ( $title && $title instanceof Title && $title->exists() );
+ return !( $title && $title instanceof Title && $title->exists() );
}
/**
$tmpName = tempnam( wfTempDir(), "" );
if ( !file_exists( $filePath ) ) {
throw new Exception( "$filePath doesn't exist!" );
- };
+ }
if ( !copy( $filePath, $tmpName ) ) {
throw new Exception( "couldn't copy $filePath to $tmpName" );
throw new Exception( "couldn't stat $tmpName" );
}
- $_FILES[ $fieldName ] = array(
- 'name' => $fileName,
- 'type' => $type,
- 'tmp_name' => $tmpName,
- 'size' => $size,
- 'error' => null
+ $_FILES[$fieldName] = array(
+ 'name' => $fileName,
+ 'type' => $type,
+ 'tmp_name' => $tmpName,
+ 'size' => $size,
+ 'error' => null
);
return true;
}
- function fakeUploadChunk( $fieldName, $fileName, $type, & $chunkData ) {
+ function fakeUploadChunk( $fieldName, $fileName, $type, & $chunkData ) {
$tmpName = tempnam( wfTempDir(), "" );
// copy the chunk data to temp location:
if ( !file_put_contents( $tmpName, $chunkData ) ) {
throw new Exception( "couldn't stat $tmpName" );
}
- $_FILES[ $fieldName ] = array(
- 'name' => $fileName,
- 'type' => $type,
- 'tmp_name' => $tmpName,
- 'size' => $size,
- 'error' => null
+ $_FILES[$fieldName] = array(
+ 'name' => $fileName,
+ 'type' => $type,
+ 'tmp_name' => $tmpName,
+ 'size' => $size,
+ 'error' => null
);
}
function clearTempUpload() {
- if( isset( $_FILES['file']['tmp_name'] ) ) {
+ if ( isset( $_FILES['file']['tmp_name'] ) ) {
$tmp = $_FILES['file']['tmp_name'];
- if( file_exists( $tmp ) ) {
+ if ( file_exists( $tmp ) ) {
unlink( $tmp );
}
}
try {
$randomImageGenerator = new RandomImageGenerator();
$filePaths = $randomImageGenerator->writeImages( 1, $extension, wfTempDir() );
- }
- catch ( Exception $e ) {
+ } catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
$this->deleteFileByContent( $filePath );
- if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
+ if ( !$this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
'filename' => $fileName,
'file' => 'dummy content',
'comment' => 'dummy comment',
- 'text' => "This is the page text for $fileName",
+ 'text' => "This is the page text for $fileName",
);
$exception = false;
$this->deleteFileByFileName( $fileName );
- if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
+ if ( !$this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
'filename' => $fileName,
'file' => 'dummy content',
'comment' => 'dummy comment',
- 'text' => "This is the page text for $fileName",
+ 'text' => "This is the page text for $fileName",
);
$exception = false;
try {
$randomImageGenerator = new RandomImageGenerator();
$filePaths = $randomImageGenerator->writeImages( 2, $extension, wfTempDir() );
- }
- catch ( Exception $e ) {
+ } catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
'filename' => $fileName,
'file' => 'dummy content',
'comment' => 'dummy comment',
- 'text' => "This is the page text for $fileName",
+ 'text' => "This is the page text for $fileName",
);
// first upload .... should succeed
- if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[0] ) ) {
+ if ( !$this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[0] ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
// second upload with the same name (but different content)
- if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[1] ) ) {
+ if ( !$this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[1] ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
try {
$randomImageGenerator = new RandomImageGenerator();
$filePaths = $randomImageGenerator->writeImages( 1, $extension, wfTempDir() );
- }
- catch ( Exception $e ) {
+ } catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
'filename' => $fileNames[0],
'file' => 'dummy content',
'comment' => 'dummy comment',
- 'text' => "This is the page text for " . $fileNames[0],
+ 'text' => "This is the page text for " . $fileNames[0],
);
- if (! $this->fakeUploadFile( 'file', $fileNames[0], $mimeType, $filePaths[0] ) ) {
+ if ( !$this->fakeUploadFile( 'file', $fileNames[0], $mimeType, $filePaths[0] ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
// second upload with the same content (but different name)
- if (! $this->fakeUploadFile( 'file', $fileNames[1], $mimeType, $filePaths[0] ) ) {
+ if ( !$this->fakeUploadFile( 'file', $fileNames[1], $mimeType, $filePaths[0] ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
'filename' => $fileNames[1],
'file' => 'dummy content',
'comment' => 'dummy comment',
- 'text' => "This is the page text for " . $fileNames[1],
+ 'text' => "This is the page text for " . $fileNames[1],
);
$exception = false;
try {
$randomImageGenerator = new RandomImageGenerator();
$filePaths = $randomImageGenerator->writeImages( 1, $extension, wfTempDir() );
- }
- catch ( Exception $e ) {
+ } catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
$this->deleteFileByFileName( $fileName );
$this->deleteFileByContent( $filePath );
- if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
+ if ( !$this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
$params = array(
'action' => 'upload',
- 'stash' => 1,
+ 'stash' => 1,
'filename' => $fileName,
'file' => 'dummy content',
'comment' => 'dummy comment',
- 'text' => "This is the page text for $fileName",
+ 'text' => "This is the page text for $fileName",
);
$exception = false;
'filekey' => $filekey,
'filename' => $fileName,
'comment' => 'dummy comment',
- 'text' => "This is the page text for $fileName, altered",
+ 'text' => "This is the page text for $fileName, altered",
);
$this->clearFakeUploads();
$this->deleteFileByFilename( $fileName );
unlink( $filePath );
}
-
-
+
/**
* @depends testLogin
*/
$filePath = wfTempDir() . '/Oberaargletscher_from_Oberaar.jpg';
try {
// Only download if the file is not avaliable in the temp location:
- if( !is_file( $filePath ) ){
- copy($url, $filePath);
+ if ( !is_file( $filePath ) ) {
+ copy( $url, $filePath );
}
- }
- catch ( Exception $e ) {
+ } catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
// Base upload params:
$params = array(
'action' => 'upload',
- 'stash' => 1,
+ 'stash' => 1,
'filename' => $fileName,
'filesize' => $fileSize,
'offset' => 0,
);
-
+
// Upload chunks
$chunkSessionKey = false;
$resultOffset = 0;
// Open the file:
- $handle = @fopen ($filePath, "r");
- if( $handle === false ){
+ $handle = @fopen( $filePath, "r" );
+ if ( $handle === false ) {
$this->markTestIncomplete( "could not open file: $filePath" );
}
- while (!feof ($handle)) {
+ while ( !feof( $handle ) ) {
// Get the current chunk
$chunkData = @fread( $handle, $chunkSize );
// Upload the current chunk into the $_FILE object:
$this->fakeUploadChunk( 'chunk', 'blob', $mimeType, $chunkData );
-
+
// Check for chunkSessionKey
- if( !$chunkSessionKey ){
+ if ( !$chunkSessionKey ) {
// Upload fist chunk ( and get the session key )
try {
list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
$this->assertTrue( isset( $result['upload'] ) );
$this->assertTrue( isset( $result['upload']['filekey'] ) );
// If we don't get a session key mark test incomplete.
- if( ! isset( $result['upload']['filekey'] ) ){
+ if ( !isset( $result['upload']['filekey'] ) ) {
$this->markTestIncomplete( "no filekey provided" );
}
$chunkSessionKey = $result['upload']['filekey'];
// Make sure we got a valid chunk continue:
$this->assertTrue( isset( $result['upload'] ) );
$this->assertTrue( isset( $result['upload']['filekey'] ) );
-
+
// Check if we were on the last chunk:
- if( $params['offset'] + $chunkSize >= $fileSize ){
+ if ( $params['offset'] + $chunkSize >= $fileSize ) {
$this->assertEquals( 'Success', $result['upload']['result'] );
break;
} else {
// update $resultOffset
$resultOffset = $result['upload']['offset'];
}
- }
- fclose ($handle);
-
+ }
+ fclose( $handle );
+
// Check that we got a valid file result:
- wfDebug( __METHOD__ . " hohoh filesize {$fileSize} info {$result['upload']['imageinfo']['size']}\n\n");
+ wfDebug( __METHOD__ . " hohoh filesize {$fileSize} info {$result['upload']['imageinfo']['size']}\n\n" );
$this->assertEquals( $fileSize, $result['upload']['imageinfo']['size'] );
$this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] );
$this->assertTrue( isset( $result['upload']['filekey'] ) );
'filekey' => $filekey,
'filename' => $fileName,
'comment' => 'dummy comment',
- 'text' => "This is the page text for $fileName, altered",
+ 'text' => "This is the page text for $fileName, altered",
);
$this->clearFakeUploads();
$exception = false;