jenkins-bot has submitted this change and it was merged.

Change subject: Add a way to easily test Special:TranslationStash in tests
......................................................................


Add a way to easily test Special:TranslationStash in tests

Allow adding testing usernames to $wgTranslateTestUsers
and then using it with ?integrationtesting=activatestash.

Change-Id: I1ca4f9e6796250ffdc8af2e1383c87acb02314be
---
M Translate.php
M specials/SpecialTranslationStash.php
M stash/TranslationStashStorage.php
3 files changed, 52 insertions(+), 3 deletions(-)

Approvals:
  Amire80: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Translate.php b/Translate.php
index 9203a06..ef2829a 100644
--- a/Translate.php
+++ b/Translate.php
@@ -620,6 +620,13 @@
  */
 $wgTranslateUseTux = true;
 
+/**
+ * List of user names that are allowed to alter their privileges and do other
+ * things. Used for supporting integration testing.
+ * @since 2013.10
+ */
+$wgTranslateTestUsers = array();
+
 # </source>
 
 /** @cond cli_support */
diff --git a/specials/SpecialTranslationStash.php 
b/specials/SpecialTranslationStash.php
index 5a9bbfe..5ebcac5 100644
--- a/specials/SpecialTranslationStash.php
+++ b/specials/SpecialTranslationStash.php
@@ -21,8 +21,7 @@
                $this->setHeaders();
                $out = $this->getOutput();
 
-               if ( !TranslateSandbox::isSandboxed( $this->getUser() ) ) {
-                       // Not a sandboxed user, redirect to Special:Translate
+               if ( !$this->hasPermissionToUse() ) {
                        $out->redirect( Title::newMainPage()->getLocalUrl() );
 
                        return;
@@ -33,6 +32,39 @@
        }
 
        /**
+        * Checks that the user is in the sandbox. Also handles special 
overrides
+        * mainly used for integration testing.
+        *
+        * @return bool
+        */
+       protected function hasPermissionToUse() {
+               global $wgTranslateTestUsers;
+
+               $request = $this->getRequest();
+               $user = $this->getUser();
+
+               if ( in_array( $user->getName(), $wgTranslateTestUsers, true ) 
) {
+                       if ( $request->getVal( 'integrationtesting' ) === 
'activatestash' ) {
+                               $user->addGroup( 'translate-sandboxed' );
+
+                               return true;
+                       } elseif ( $request->getVal( 'integrationtesting' ) === 
'deactivatestash' ) {
+                               $user->removeGroup( 'translate-sandboxed' );
+                               $stash = new TranslationStashStorage( wfGetDB( 
DB_MASTER ) );
+                               $stash->deleteTranslations( $user );
+
+                               return false;
+                       }
+               }
+
+               if ( !TranslateSandbox::isSandboxed( $user ) ) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       /**
         * Generates the whole page html and appends it to output
         */
        protected function showPage() {
diff --git a/stash/TranslationStashStorage.php 
b/stash/TranslationStashStorage.php
index 8f5865b..6b9ea35 100644
--- a/stash/TranslationStashStorage.php
+++ b/stash/TranslationStashStorage.php
@@ -4,7 +4,7 @@
  *
  * @file
  * @author Niklas Laxström
- * @license GPL2+
+ * @license GPL-2.0+
  */
 
 /**
@@ -64,4 +64,14 @@
 
                return $objects;
        }
+
+       /**
+        * Delete all stashed translations for the given user.
+        * @param User $user
+        * @since 2013.10
+        */
+       public function deleteTranslations( User $user ) {
+               $conds = array( 'ts_user' => $user->getId() );
+               $this->db->delete( $this->dbTable, $conds, __METHOD__ );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/89203
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1ca4f9e6796250ffdc8af2e1383c87acb02314be
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to