TYPO3 CMS  TYPO3_7-6
ExtendedFileUtilityTest.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  */
18 
23 {
27  protected function setUp()
28  {
29  $GLOBALS['LANG'] = $this->getMock(\TYPO3\CMS\Lang\LanguageService::class, ['sL']);
30  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, []);
31  }
32 
36  public function folderHasFilesInUseReturnsTrueIfItHasFiles()
37  {
38  $fileUid = 1;
39  $file = $this->getMock(File::class, ['getUid'], [], '', false);
40  $file->expects($this->once())->method('getUid')->will($this->returnValue($fileUid));
41 
42  $folder = $this->getMock(Folder::class, ['getFiles'], [], '', false);
43  $folder->expects($this->once())
44  ->method('getFiles')->with(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true)
45  ->will($this->returnValue([$file])
46  );
47 
49  $subject = $this->getMock(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class, ['addFlashMessage'], [], '');
50  $GLOBALS['TYPO3_DB']->expects($this->once())
51  ->method('exec_SELECTcountRows')->with('*', 'sys_refindex', 'deleted=0 AND ref_table="sys_file" AND ref_uid IN (' . $fileUid . ') AND tablename<>"sys_file_metadata"')
52  ->will($this->returnValue(1));
53 
54  $GLOBALS['LANG']->expects($this->at(0))->method('sL')
55  ->with('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFilesWithReferences')
56  ->will($this->returnValue('folderNotDeletedHasFilesWithReferences'));
57  $GLOBALS['LANG']->expects($this->at(1))->method('sL')
58  ->with('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFilesWithReferences')
59  ->will($this->returnValue('folderNotDeletedHasFilesWithReferences'));
60 
61  $result = $subject->folderHasFilesInUse($folder);
62  $this->assertTrue($result);
63  }
64 
68  public function folderHasFilesInUseReturnsFalseIfItHasNoFiles()
69  {
70  $folder = $this->getMock(Folder::class, ['getFiles'], [], '', false);
71  $folder->expects($this->once())->method('getFiles')->with(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true)->will(
72  $this->returnValue([])
73  );
74 
76  $subject = $this->getMock(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class, ['addFlashMessage'], [], '');
77  $this->assertFalse($subject->folderHasFilesInUse($folder));
78  }
79 }
const FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
Definition: Folder.php:68
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']