9 protected function setUp() {
12 $filename =
'Foo.png';
17 'name' =>
'local-migratefilerepolayouttest',
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",
28 $dbMock = $this->getMockBuilder(
'DatabaseMysqli' )
29 ->disableOriginalConstructor()
32 $imageRow =
new stdClass;
33 $imageRow->img_name = $filename;
34 $imageRow->img_sha1 = sha1( $this->
text );
36 $dbMock->expects( $this->any() )
38 ->will( $this->onConsecutiveCalls(
39 new FakeResultWrapper( [ $imageRow ] ),
40 new FakeResultWrapper( [] ),
41 new FakeResultWrapper( [] )
44 $repoMock = $this->getMockBuilder(
'LocalRepo' )
45 ->setMethods( [
'getMasterDB' ] )
46 ->setConstructorArgs( [ [
47 'name' =>
'migratefilerepolayouttest',
53 ->expects( $this->any() )
54 ->method(
'getMasterDB' )
55 ->will( $this->returnValue( $dbMock ) );
57 $this->migratorMock = $this->getMockBuilder(
'MigrateFileRepoLayout' )
58 ->setMethods( [
'getRepo' ] )->getMock();
60 ->expects( $this->any() )
62 ->will( $this->returnValue( $repoMock ) );
65 'migratefilelayout-test-',
'png',
wfTempDir() )->getPath();
67 file_put_contents( $this->tmpFilepath, $this->
text );
69 $hashPath = $repoMock->getHashPath( $filename );
74 $hashPath . $filename,
102 $this->migratorMock->loadParamsAndArgs(
104 [
'oldlayout' =>
'name',
'newlayout' =>
'sha1' ]
109 $this->migratorMock->execute();
113 $sha1 = sha1( $this->
text );
115 $expectedOriginalFilepath = $this->tmpPrefix
117 . substr( $sha1, 0, 1 )
119 . substr( $sha1, 1, 1 )
121 . substr( $sha1, 2, 1 )
126 file_get_contents( $expectedOriginalFilepath ),
128 'New sha1 file should be exist and have the right contents'
131 $expectedPublicFilepath = $this->tmpPrefix .
'-public/f/f8/Foo.png';
134 file_get_contents( $expectedPublicFilepath ),
136 'Existing name file should still and have the right contents'