TYPO3 CMS  TYPO3_6-2
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 = array();
41 
45  protected function setUp() {
46  $this->storageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
47  $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
48 
49  $this->folderMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
50  $this->folderMock->expects($this->any())->method('getStorage')->willReturn($this->storageMock);
51 
52  $this->storageMock->expects($this->any())->method('getProcessingFolder')->willReturn($this->folderMock);
53 
54  $this->databaseRow = array(
55  'uid' => '1234567',
56  'identifier' => 'dummy.txt',
57  'name' => $this->getUniqueId('dummy_'),
58  'storage' => $this->storageMock->getUid(),
59  );
60  }
61 
67  protected function getFileFixture($dbRow = NULL, $storageMock = NULL) {
68  return new File($dbRow ?: $this->databaseRow, $storageMock ?: $this->storageMock);
69  }
70 
76  protected function getProcessedFileFixture($dbRow = NULL, $originalFile = NULL) {
77  if ($originalFile === NULL) {
78  $originalFile = $this->getFileFixture();
79  }
80  return new ProcessedFile($originalFile, 'dummy', array(), $dbRow ?: $this->databaseRow);
81  }
82 
87  $processedFileObject = $this->getProcessedFileFixture();
88  $this->assertSame($this->databaseRow, $processedFileObject->getProperties());
89  }
90 
95  $this->storageMock->expects($this->once())->method('deleteFile');
96  $processedDatabaseRow = $this->databaseRow;
97  $processedDatabaseRow['identifier'] = 'processed_dummy.txt';
98  $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
99  $processedFile->delete(TRUE);
100  }
101 
106  $this->storageMock->expects($this->never())->method('deleteFile');
107  $processedDatabaseRow = $this->databaseRow;
108  $processedDatabaseRow['identifier'] = NULL;
109  $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
110  $processedFile->delete(TRUE);
111  }
112 }
getProcessedFileFixture($dbRow=NULL, $originalFile=NULL)