Merge "Blacklist Google Glass web browser from JS"
[mediawiki.git] / tests / phpunit / mocks / filebackend / MockFileBackend.php
blob49aefbd1475aa83eea2f84c9850df3ecfdefb384
1 <?php
2 /**
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
20 * @file
21 * @ingroup FileBackend
22 * @author Antoine Musso <hashar@free.fr>
25 /**
26 * Class simulating a backend store.
28 * @ingroup FileBackend
29 * @since 1.22
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 ) {
41 return true;
44 protected function doCreateInternal( array $params ) {
45 if ( isset( $params['content'] ) ) {
46 $content = $params['content'];
47 } else {
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" );
80 return array(
81 'mtime' => wfTimestamp( TS_MW ),
82 'size' => strlen( $this->mocked[$src] ),
83 # No sha1, stat does not need it.
85 } else {
86 $this->debug( "('$src') not found" );
87 return false;
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 )
100 return $tmpFiles;
103 protected function doDirectoryExists( $container, $dir, array $params ) {
104 $this->debug();
105 return true;
108 public function getDirectoryListInternal( $container, $dir, array $params ) {
109 $this->debug();
110 return array();
113 public function getFileListInternal( $container, $dir, array $params ) {
114 $this->debug();
115 return array();
118 protected function directoriesAreVirtual() {
119 $this->debug();
120 return true;