TYPO3 CMS  TYPO3_7-6
ProcessedFileTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
30  protected $folderMock;
31 
35  protected $storageMock;
36 
40  protected $databaseRow = [];
41 
45  protected function setUp()
46  {
47  $this->storageMock = $this->getMock(ResourceStorage::class, [], [], '', false);
48  $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
49 
50  $this->folderMock = $this->getMock(Folder::class, [], [], '', false);
51  $this->folderMock->expects($this->any())->method('getStorage')->willReturn($this->storageMock);
52 
53  $this->storageMock->expects($this->any())->method('getProcessingFolder')->willReturn($this->folderMock);
54 
55  $this->databaseRow = [
56  'uid' => '1234567',
57  'identifier' => 'dummy.txt',
58  'name' => $this->getUniqueId('dummy_'),
59  'storage' => $this->storageMock->getUid(),
60  ];
61  }
62 
68  protected function getFileFixture($dbRow = null, $storageMock = null)
69  {
70  return new File($dbRow ?: $this->databaseRow, $storageMock ?: $this->storageMock);
71  }
72 
78  protected function getProcessedFileFixture($dbRow = null, $originalFile = null)
79  {
80  if ($originalFile === null) {
81  $originalFile = $this->getFileFixture();
82  }
83  return new ProcessedFile($originalFile, 'dummy', [], $dbRow ?: $this->databaseRow);
84  }
85 
90  {
91  $processedFileObject = $this->getProcessedFileFixture();
92  $this->assertSame($this->databaseRow, $processedFileObject->getProperties());
93  }
94 
99  {
100  $this->storageMock->expects($this->once())->method('deleteFile');
101  $processedDatabaseRow = $this->databaseRow;
102  $processedDatabaseRow['identifier'] = 'processed_dummy.txt';
103  $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
104  $processedFile->delete(true);
105  }
106 
111  {
112  $this->storageMock->expects($this->never())->method('deleteFile');
113  $processedDatabaseRow = $this->databaseRow;
114  $processedDatabaseRow['identifier'] = null;
115  $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
116  $processedFile->delete(true);
117  }
118 }
getProcessedFileFixture($dbRow=null, $originalFile=null)