Fix issues identified by SpaceBeforeSingleLineComment sniff
[lhc/web/wiklou.git] / tests / phpunit / includes / EditPageTest.php
index 15778e4..51f0083 100644 (file)
  */
 class EditPageTest extends MediaWikiLangTestCase {
 
+       protected function setUp() {
+               global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
+
+               parent::setUp();
+
+               $this->setMwGlobals( array(
+                       'wgExtraNamespaces' => $wgExtraNamespaces,
+                       'wgNamespaceContentModels' => $wgNamespaceContentModels,
+                       'wgContentHandlers' => $wgContentHandlers,
+                       'wgContLang' => $wgContLang,
+               ) );
+
+               $wgExtraNamespaces[12312] = 'Dummy';
+               $wgExtraNamespaces[12313] = 'Dummy_talk';
+
+               $wgNamespaceContentModels[12312] = "testing";
+               $wgContentHandlers["testing"] = 'DummyContentHandlerForTesting';
+
+               MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
+               $wgContLang->resetNamespaces(); # reset namespace cache
+       }
+
        /**
         * @dataProvider provideExtractSectionTitle
         * @covers EditPage::extractSectionTitle
@@ -116,7 +138,7 @@ class EditPageTest extends MediaWikiLangTestCase {
                        $page->doEditContent( $content, "base text for test" );
                        $this->forceRevisionDate( $page, '20120101000000' );
 
-                       //sanity check
+                       // sanity check
                        $page->clear();
                        $currentText = ContentHandler::getContentText( $page->getContent() );
 
@@ -313,7 +335,7 @@ hello
                $textWithNewSectionAdded = "$text\n$newSection";
 
                return array(
-                       array( #0
+                       array( # 0
                                $text,
                                '',
                                'hello',
@@ -321,7 +343,7 @@ hello
                                'hello'
                        ),
 
-                       array( #1
+                       array( # 1
                                $text,
                                '1',
                                $sectionOne,
@@ -329,7 +351,7 @@ hello
                                $textWithNewSectionOne,
                        ),
 
-                       array( #2
+                       array( # 2
                                $text,
                                'new',
                                'hello',
@@ -358,14 +380,14 @@ hello
        public static function provideAutoMerge() {
                $tests = array();
 
-               $tests[] = array( #0: plain conflict
+               $tests[] = array( # 0: plain conflict
                        "Elmo", # base edit user
                        "one\n\ntwo\n\nthree\n",
-                       array( #adam's edit
+                       array( # adam's edit
                                'wpStarttime' => 1,
                                'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
                        ),
-                       array( #berta's edit
+                       array( # berta's edit
                                'wpStarttime' => 2,
                                'wpTextbox1' => "(one)\n\ntwo\n\nthree\n",
                        ),
@@ -374,14 +396,14 @@ hello
                        'expected edit conflict', # message
                );
 
-               $tests[] = array( #1: successful merge
+               $tests[] = array( # 1: successful merge
                        "Elmo", # base edit user
                        "one\n\ntwo\n\nthree\n",
-                       array( #adam's edit
+                       array( # adam's edit
                                'wpStarttime' => 1,
                                'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
                        ),
-                       array( #berta's edit
+                       array( # berta's edit
                                'wpStarttime' => 2,
                                'wpTextbox1' => "one\n\ntwo\n\nTHREE\n",
                        ),
@@ -402,15 +424,15 @@ hello
                // generate expected text after merge
                $expected = str_replace( 'one', 'ONE', str_replace( 'three', 'THREE', $text ) );
 
-               $tests[] = array( #2: merge in section
+               $tests[] = array( # 2: merge in section
                        "Elmo", # base edit user
                        $text,
-                       array( #adam's edit
+                       array( # adam's edit
                                'wpStarttime' => 1,
                                'wpTextbox1' => str_replace( 'one', 'ONE', $section ),
                                'wpSection' => '1'
                        ),
-                       array( #berta's edit
+                       array( # berta's edit
                                'wpStarttime' => 2,
                                'wpTextbox1' => str_replace( 'three', 'THREE', $section ),
                                'wpSection' => '1'
@@ -443,7 +465,7 @@ hello
        ) {
                $this->checkHasDiff3();
 
-               //create page
+               // create page
                $ns = $this->getDefaultWikitextNS();
                $title = Title::newFromText( 'EditPageTest_testAutoMerge', $ns );
                $page = WikiPage::factory( $title );
@@ -499,4 +521,37 @@ hello
                $this->assertEdit( 'EditPageTest_testAutoMerge', null, 'Berta', $bertasEdit,
                        $expectedCode, $expectedText, $message );
        }
+
+       /**
+        * @depends testAutoMerge
+        */
+       public function testCheckDirectEditingDisallowed_forNonTextContent() {
+               $title = Title::newFromText( 'Dummy:NonTextPageForEditPage' );
+               $page = WikiPage::factory( $title );
+
+               $article = new Article( $title );
+               $article->getContext()->setTitle( $title );
+               $ep = new EditPage( $article );
+               $ep->setContextTitle( $title );
+
+               $user = $GLOBALS['wgUser'];
+
+               $edit = array(
+                       'wpTextbox1' => serialize( 'non-text content' ),
+                       'wpEditToken' => $user->getEditToken(),
+                       'wpEdittime' => '',
+                       'wpStarttime' => wfTimestampNow()
+               );
+
+               $req = new FauxRequest( $edit, true );
+               $ep->importFormData( $req );
+
+               $this->setExpectedException(
+                       'MWException',
+                       'This content model is not supported: testing'
+               );
+
+               $ep->internalAttemptSave( $result, false );
+       }
+
 }