3 * Simulation (mock) of a backend storage.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup FileBackend
22 * @author Antoine Musso <hashar@free.fr>
26 * Class simulating a backend store.
28 * @ingroup FileBackend
31 class MockFileBackend
extends FileBackendStore
{
33 protected $mocked = array();
35 /** Poor man debugging */
36 protected function debug( $msg = '' ) {
37 wfDebug( wfGetCaller() . "$msg\n" );
40 public function isPathUsableInternal( $storagePath ) {
44 protected function doCreateInternal( array $params ) {
45 if ( isset( $params['content'] ) ) {
46 $content = $params['content'];
48 $content = 'Default mocked file content';
50 $this->debug( serialize( $params ) );
51 $dst = $params['dst'];
52 $this->mocked
[$dst] = $content;
53 return Status
::newGood();
56 protected function doStoreInternal( array $params ) {
57 $this->debug( serialize( $params ) );
58 return $this->doCreateInternal( $params );
61 protected function doCopyInternal( array $params ) {
62 $this->debug( serialize( $params ) );
63 $src = $params['src'];
64 $dst = $params['dst'];
65 $this->mocked
[$dst] = $this->mocked
[$src];
66 return Status
::newGood();
69 protected function doDeleteInternal( array $params ) {
70 $this->debug( serialize( $params ) );
71 $src = $params['src'];
72 unset( $this->mocked
[$src] );
73 return Status
::newGood();
76 protected function doGetFileStat( array $params ) {
77 $src = $params['src'];
78 if ( array_key_exists( $src, $this->mocked
) ) {
79 $this->debug( "('$src') found" );
81 'mtime' => wfTimestamp( TS_MW
),
82 'size' => strlen( $this->mocked
[$src] ),
83 # No sha1, stat does not need it.
86 $this->debug( "('$src') not found" );
91 protected function doGetLocalCopyMulti( array $params ) {
92 $tmpFiles = array(); // (path => MockFSFile)
94 $this->debug( '(' . serialize( $params ) . ')' );
95 foreach ( $params['srcs'] as $src ) {
96 $tmpFiles[$src] = new MockFSFile(
97 wfTempDir() . '/' . wfRandomString( 32 )
103 protected function doDirectoryExists( $container, $dir, array $params ) {
108 public function getDirectoryListInternal( $container, $dir, array $params ) {
113 public function getFileListInternal( $container, $dir, array $params ) {
118 protected function directoriesAreVirtual() {