PageTranslationTaggingTest.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class PageTranslationTaggingText extends MediaWikiTestCase {
00008     protected function setUp() {
00009         parent::setUp();
00010 
00011         global $wgHooks;
00012         $this->setMwGlobals( array(
00013             'wgHooks' => $wgHooks,
00014             'wgTranslateCC' => array(),
00015             'wgTranslateMessageIndex' => array( 'DatabaseMessageIndex' ),
00016             'wgTranslateWorkflowStates' => false,
00017             'wgEnablePageTranslation' => true,
00018             'wgTranslateGroupFiles' => array(),
00019             'wgTranslateTranslationServices' => array(),
00020         ) );
00021         TranslateHooks::setupTranslate();
00022         $wgHooks['TranslatePostInitGroups'] = array();
00023         MessageGroups::clearCache();
00024         MessageIndexRebuildJob::newJob()->run();
00025     }
00026 
00027     public function testNormalPage() {
00028         $title = Title::newFromText( 'Fréttinga' );
00029         $this->assertNotNull( $title, 'Title is valid' );
00030         $page = WikiPage::factory( $title );
00031         $this->assertNotNull( $page, 'WikiPage is valid' );
00032         $translatablePage = TranslatablePage::newFromTitle( $title );
00033 
00034         $page->doEdit( 'kissa', 'Test case' );
00035 
00036         $this->assertFalse( $translatablePage->getReadyTag(), 'No ready tag was added' );
00037         $this->assertFalse( $translatablePage->getMarkedTag(), 'No marked tag was added' );
00038     }
00039 
00040     public function testTranslatablePage() {
00041         $title = Title::newFromText( 'Fréttinga' );
00042         $this->assertNotNull( $title, 'Title is valid' );
00043         $page = WikiPage::factory( $title );
00044         $this->assertNotNull( $page, 'WikiPage is valid' );
00045         $translatablePage = TranslatablePage::newFromTitle( $title );
00046 
00047         $status = $page->doEdit( '<translate>kissa</translate>', 'Test case' );
00048         $latest = $status->value['revision']->getId();
00049 
00050         $this->assertSame( $latest, $translatablePage->getReadyTag(), 'Ready tag was added' );
00051         $this->assertFalse( $translatablePage->getMarkedTag(), 'No marked tag was added' );
00052     }
00053 
00054     public function testTranslatablePageWithMarked() {
00055         $title = Title::newFromText( 'Fréttinga' );
00056         $this->assertNotNull( $title, 'Title is valid' );
00057         $page = WikiPage::factory( $title );
00058         $this->assertNotNull( $page, 'WikiPage is valid' );
00059         $translatablePage = TranslatablePage::newFromTitle( $title );
00060 
00061         $status = $page->doEdit( '<translate>koira</translate>', 'Test case' );
00062         $latest = $status->value['revision']->getId();
00063 
00064         $translatablePage->addMarkedTag( $latest, array( 'foo' ) );
00065         $this->assertSame( $latest, $translatablePage->getReadyTag(), 'Ready tag was added' );
00066         $this->assertSame( $latest, $translatablePage->getMarkedTag(), 'Marked tag was added' );
00067         $page->updateRestrictions( array( 'edit' => 'sysop' ), 'Test case' );
00068 
00069         $newLatest = $latest + 1;
00070         $this->assertSame(
00071             $newLatest,
00072             $translatablePage->getReadyTag(),
00073             'Ready tag was updated after protection'
00074         );
00075         $this->assertSame(
00076             $latest,
00077             $translatablePage->getMarkedTag(),
00078             'Marked tag was not updated after protection'
00079         );
00080     }
00081 
00082     public function testTranslationPageRestrictions() {
00083         $superUser = new MockSuperUser();
00084         $title = Title::newFromText( 'Translatable page' );
00085         $page = WikiPage::factory( $title );
00086         $status = $page->doEdit(
00087             '<translate>Hello</translate>',
00088             'New page',
00089             0,
00090             false,
00091             $superUser
00092         );
00093         $revision = $status->value['revision']->getId();
00094         $translatablePage = TranslatablePage::newFromRevision( $title, $revision );
00095         $translatablePage->addMarkedTag( $revision );
00096         MessageGroups::clearCache();
00097 
00098         $translationPage = Title::newFromText( 'Translatable page/fi' );
00099         TranslateRenderJob::newJob( $translationPage )->run();
00100         $this->assertTrue( $translationPage->userCan( 'read', $superUser ),
00101             'Users can read existing translation pages' );
00102         $this->assertFalse( $translationPage->userCan( 'edit', $superUser ),
00103             'Users can not edit existing translation pages' );
00104 
00105         $translationPage = Title::newFromText( 'Translatable page/ab' );
00106         $this->assertTrue( $translationPage->userCan( 'read', $superUser ),
00107             'Users can read non-existing translation pages' );
00108         $this->assertFalse( $translationPage->userCan( 'edit', $superUser ),
00109             'Users can not edit non-existing translation pages' );
00110     }
00111 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3