Hashar has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/61276


Change subject: (WIP) Mock filebackend for parser tests (WIP)
......................................................................

(WIP) Mock filebackend for parser tests (WIP)

DO NO SUBMIT REALLY PLEASE :-(
DO NO SUBMIT REALLY PLEASE :-|
DO NO SUBMIT REALLY PLEASE 8-)

Change-Id: Iccdff67222e66d48d01dd1596d09df2ea24b8c2a
---
M includes/AutoLoader.php
A includes/filebackend/MockFile.php
A includes/filebackend/MockFileBackend.php
M tests/phpunit/includes/parser/NewParserTest.php
4 files changed, 152 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/76/61276/1

diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 4813d45..8298e89 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -560,6 +560,8 @@
        'FSFileBackendDirList' => 'includes/filebackend/FSFileBackend.php',
        'FSFileBackendFileList' => 'includes/filebackend/FSFileBackend.php',
        'FSFileOpHandle' => 'includes/filebackend/FSFileBackend.php',
+       'MockFile' => 'includes/filebackend/MockFile.php',
+       'MockFileBackend' => 'includes/filebackend/MockFileBackend.php',
        'SwiftFileBackend' => 'includes/filebackend/SwiftFileBackend.php',
        'SwiftFileBackendList' => 'includes/filebackend/SwiftFileBackend.php',
        'SwiftFileBackendDirList' => 
'includes/filebackend/SwiftFileBackend.php',
diff --git a/includes/filebackend/MockFile.php 
b/includes/filebackend/MockFile.php
new file mode 100644
index 0000000..06c3ad9
--- /dev/null
+++ b/includes/filebackend/MockFile.php
@@ -0,0 +1,33 @@
+<?php
+class MockFile extends FSFile {
+       private $sha1Base36 = null; // File Sha1Base36
+
+       public function exists() {
+               return true;
+       }
+
+       public function getSize() {
+               return 1911;
+       }
+
+       public function getTimestamp() {
+               return wfTimestamp( TS_MW );
+       }
+
+       public function getMimeType() {
+               return 'text/mock';
+       }
+
+       public function getProps( $ext = true ) {
+               return array(
+                       'fileExists' => $this->exists(),
+                       'size' => $this->getSize(),
+                       'file-mime' => $this->getMimeType(),
+                       'sha1' => $this->getSha1Base36(),
+               );
+       }
+
+       public function getSha1Base36( $recache = false ) {
+               return '1234567890123456789012345678901';
+       }
+}
diff --git a/includes/filebackend/MockFileBackend.php 
b/includes/filebackend/MockFileBackend.php
new file mode 100644
index 0000000..14cef15
--- /dev/null
+++ b/includes/filebackend/MockFileBackend.php
@@ -0,0 +1,115 @@
+<?php
+/**
+ * Simulation (mock) of a backend storage.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup FileBackend
+ * @author Antoine Musso <[email protected]>
+ */
+
+/**
+ * Class simulating a backend store.
+ *
+ * @ingroup FileBackend
+ * @since 1.22
+ */
+class MockFileBackend extends FileBackendStore {
+
+       protected $mocked = array();
+
+       /** Poor man debugging */
+       protected function debug( $msg = '' ) {
+               wfDebug( wfGetCaller() . "$msg\n" );
+       }
+
+       public function isPathUsableInternal( $storagePath ) {
+               return true;
+       }
+
+       /** strip 'mwstore://' */
+       public function resolveToFSPath( $path ) {
+               return substr($path, strlen('mwstore://'));
+       }
+
+       protected function doCreateInternal( array $params ) {
+               $this->debug(serialize($params));
+               $dst = $params['dst'];
+               $this->mocked[$dst] = true;  # should be $params['content']
+               return Status::newGood();
+       }
+
+       protected function doStoreInternal( array $params ) {
+               $this->debug(serialize($params));
+               return $this->doCreateInternal( $params );
+       }
+
+       protected function doCopyInternal( array $params ) {
+               $this->debug(serialize($params));
+               $src = $params['src'];
+               $dst = $params['dst'];
+               $this->mocked[$dst] = $this->mocked[$src];
+               return Status::newGood();
+       }
+
+       protected function doDeleteInternal( array $params ) {
+               $this->debug(serialize($params));
+               $src = $params['src'];
+               unset( $this->mocked[$src] );
+               return Status::newGood();
+       }
+
+       protected function doGetFileStat( array $params ) {
+               $src = $params['src'];
+               if( array_key_exists( $src, $this->mocked ) ) {
+                       $this->debug( "('$src') found" );
+                       return true;
+               } else {
+                       $this->debug( "('$src') not found" );
+                       return false;
+               }
+       }
+
+       protected function doGetLocalCopyMulti( array $params ) {
+               $this->debug( '(' . serialize($params) . ')' );
+               foreach( $params['srcs'] as $src ) {
+                       $tmpFiles[$src] = new MockFile(
+                               $this->resolveToFSPath( $src )
+                       );
+               }
+               return $tmpFiles;
+       }
+
+       protected function doDirectoryExists( $container, $dir, array $params ) 
{
+               $this->debug();
+               return true;
+       }
+
+       public function getDirectoryListInternal( $container, $dir, array 
$params ) {
+               $this->debug();
+               return array_map( 'dirname', array_keys($this->mocked) );
+       }
+
+       public function getFileListInternal( $container, $dir, array $params ) {
+               $this->debug();
+               return array_keys( $this->mocked );
+       }
+
+       protected function directoriesAreVirtual() {
+               $this->debug();
+               return true;
+       }
+}
diff --git a/tests/phpunit/includes/parser/NewParserTest.php 
b/tests/phpunit/includes/parser/NewParserTest.php
index 77311b9..31f8240 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -289,7 +289,7 @@
                                $backend = self::$backendToUse;
                        }
                } else {
-                       $backend = new FSFileBackend( array(
+                       $backend = new MockFileBackend( array(
                                'name' => 'local-backend',
                                'lockManager' => 'nullLockManager',
                                'containerPaths' => array(
@@ -450,6 +450,7 @@
                $base = $this->getBaseDir();
                $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
                $backend->prepare( array( 'dir' => "$base/local-public/3/3a" ) 
);
+               wfDebug( __METHOD__ . " Storing headbg.jpg as Foobar.jpg...\n" 
);
                $backend->store( array(
                        'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => 
"$base/local-public/3/3a/Foobar.jpg"
                ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iccdff67222e66d48d01dd1596d09df2ea24b8c2a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to