MediaWiki  1.27.2
MigrateFileRepoLayoutTest.php
Go to the documentation of this file.
1 <?php
2 
4  protected $tmpPrefix;
5  protected $migratorMock;
6  protected $tmpFilepath;
7  protected $text = 'testing';
8 
9  protected function setUp() {
10  parent::setUp();
11 
12  $filename = 'Foo.png';
13 
14  $this->tmpPrefix = $this->getNewTempDirectory();
15 
16  $backend = new FSFileBackend( [
17  'name' => 'local-migratefilerepolayouttest',
18  'wikiId' => wfWikiID(),
19  'containerPaths' => [
20  'migratefilerepolayouttest-original' => "{$this->tmpPrefix}-original",
21  'migratefilerepolayouttest-public' => "{$this->tmpPrefix}-public",
22  'migratefilerepolayouttest-thumb' => "{$this->tmpPrefix}-thumb",
23  'migratefilerepolayouttest-temp' => "{$this->tmpPrefix}-temp",
24  'migratefilerepolayouttest-deleted' => "{$this->tmpPrefix}-deleted",
25  ]
26  ] );
27 
28  $dbMock = $this->getMockBuilder( 'DatabaseMysql' )
29  ->disableOriginalConstructor()
30  ->getMock();
31 
32  $imageRow = new stdClass;
33  $imageRow->img_name = $filename;
34  $imageRow->img_sha1 = sha1( $this->text );
35 
36  $dbMock->expects( $this->any() )
37  ->method( 'select' )
38  ->will( $this->onConsecutiveCalls(
39  new FakeResultWrapper( [ $imageRow ] ), // image
40  new FakeResultWrapper( [] ), // image
41  new FakeResultWrapper( [] ) // filearchive
42  ) );
43 
44  $repoMock = $this->getMock( 'LocalRepo',
45  [ 'getMasterDB' ],
46  [ [
47  'name' => 'migratefilerepolayouttest',
48  'backend' => $backend
49  ] ] );
50 
51  $repoMock
52  ->expects( $this->any() )
53  ->method( 'getMasterDB' )
54  ->will( $this->returnValue( $dbMock ) );
55 
56  $this->migratorMock = $this->getMock( 'MigrateFileRepoLayout', [ 'getRepo' ] );
57  $this->migratorMock
58  ->expects( $this->any() )
59  ->method( 'getRepo' )
60  ->will( $this->returnValue( $repoMock ) );
61 
62  $this->tmpFilepath = TempFSFile::factory( 'migratefilelayout-test-', 'png' )->getPath();
63 
64  file_put_contents( $this->tmpFilepath, $this->text );
65 
66  $hashPath = $repoMock->getHashPath( $filename );
67 
68  $status = $repoMock->store(
69  $this->tmpFilepath,
70  'public',
71  $hashPath . $filename,
73  );
74  }
75 
76  protected function deleteFilesRecursively( $directory ) {
77  foreach ( glob( $directory . '/*' ) as $file ) {
78  if ( is_dir( $file ) ) {
79  $this->deleteFilesRecursively( $file );
80  } else {
81  unlink( $file );
82  }
83  }
84 
85  rmdir( $directory );
86  }
87 
88  protected function tearDown() {
89  foreach ( glob( $this->tmpPrefix . '*' ) as $directory ) {
90  $this->deleteFilesRecursively( $directory );
91  }
92 
93  unlink( $this->tmpFilepath );
94 
95  parent::tearDown();
96  }
97 
98  public function testMigration() {
99  $this->migratorMock->loadParamsAndArgs(
100  null,
101  [ 'oldlayout' => 'name', 'newlayout' => 'sha1' ]
102  );
103 
104  ob_start();
105 
106  $this->migratorMock->execute();
107 
108  ob_end_clean();
109 
110  $sha1 = sha1( $this->text );
111 
112  $expectedOriginalFilepath = $this->tmpPrefix
113  . '-original/'
114  . substr( $sha1, 0, 1 )
115  . '/'
116  . substr( $sha1, 1, 1 )
117  . '/'
118  . substr( $sha1, 2, 1 )
119  . '/'
120  . $sha1;
121 
122  $this->assertEquals(
123  file_get_contents( $expectedOriginalFilepath ),
124  $this->text,
125  'New sha1 file should be exist and have the right contents'
126  );
127 
128  $expectedPublicFilepath = $this->tmpPrefix . '-public/f/f8/Foo.png';
129 
130  $this->assertEquals(
131  file_get_contents( $expectedPublicFilepath ),
132  $this->text,
133  'Existing name file should still and have the right contents'
134  );
135  }
136 }
static factory($prefix, $extension= '')
Make a new temporary file on the file system.
Definition: TempFSFile.php:54
const OVERWRITE
Definition: FileRepo.php:39
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1004
getNewTempDirectory()
obtains a new temporary directory
Class for a file system (FS) based file backend.