TYPO3 CMS  TYPO3_8-7
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  */
25 
29 class ExtendedFileUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
30 {
34  protected function setUp()
35  {
36  $GLOBALS['LANG'] = $this->getMockBuilder(\TYPO3\CMS\Lang\LanguageService::class)
37  ->setMethods(['sL'])
38  ->getMock();
39  }
40 
44  public function folderHasFilesInUseReturnsTrueIfItHasFiles()
45  {
46  $fileUid = 1;
47  $file = $this->getMockBuilder(File::class)
48  ->setMethods(['getUid'])
49  ->disableOriginalConstructor()
50  ->getMock();
51  $file->expects($this->once())->method('getUid')->will($this->returnValue($fileUid));
52 
53  $folder = $this->getMockBuilder(Folder::class)
54  ->setMethods(['getFiles'])
55  ->disableOriginalConstructor()
56  ->getMock();
57  $folder->expects($this->once())
58  ->method('getFiles')->with(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true)
59  ->will(
60  $this->returnValue([$file])
61  );
62 
64  $subject = $this->getMockBuilder(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class)
65  ->setMethods(['addFlashMessage'])
66  ->getMock();
67 
68  // prophetizing the DB query
69  $expressionBuilderProphet = $this->prophesize(ExpressionBuilder::class);
70  $expressionBuilderProphet->eq(Argument::cetera())->willReturn('1 = 1');
71  $expressionBuilderProphet->neq(Argument::cetera())->willReturn('1 != 1');
72  $expressionBuilderProphet->in(Argument::cetera())->willReturn('uid IN (1)');
73  $databaseStatementProphet = $this->prophesize(Statement::class);
74  $databaseStatementProphet->fetchColumn(Argument::cetera())->willReturn(1);
75  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
76  $queryBuilderProphet->getRestrictions()->willReturn(GeneralUtility::makeInstance(DefaultRestrictionContainer::class));
77  $queryBuilderProphet->count(Argument::cetera())->willReturn($queryBuilderProphet);
78  $queryBuilderProphet->from(Argument::cetera())->willReturn($queryBuilderProphet);
79  $queryBuilderProphet->where(Argument::cetera())->willReturn($queryBuilderProphet);
80  $queryBuilderProphet->createNamedParameter(Argument::cetera())->willReturn(Argument::type('string'));
81  $queryBuilderProphet->execute()->willReturn($databaseStatementProphet);
82  $queryBuilderProphet->expr()->willReturn($expressionBuilderProphet->reveal());
83  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
84  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
85  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
86 
87  $GLOBALS['LANG']->expects($this->at(0))->method('sL')
88  ->with('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:message.description.folderNotDeletedHasFilesWithReferences')
89  ->will($this->returnValue('folderNotDeletedHasFilesWithReferences'));
90  $GLOBALS['LANG']->expects($this->at(1))->method('sL')
91  ->with('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:message.header.folderNotDeletedHasFilesWithReferences')
92  ->will($this->returnValue('folderNotDeletedHasFilesWithReferences'));
93 
94  $result = $subject->folderHasFilesInUse($folder);
95  $this->assertTrue($result);
96  }
97 
101  public function folderHasFilesInUseReturnsFalseIfItHasNoFiles()
102  {
103  $folder = $this->getMockBuilder(Folder::class)
104  ->setMethods(['getFiles'])
105  ->disableOriginalConstructor()
106  ->getMock();
107  $folder->expects($this->once())->method('getFiles')->with(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true)->will(
108  $this->returnValue([])
109  );
110 
112  $subject = $this->getMockBuilder(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class)
113  ->setMethods(['addFlashMessage'])
114  ->getMock();
115  $this->assertFalse($subject->folderHasFilesInUse($folder));
116  }
117 }
static addInstance($className, $instance)
static makeInstance($className,... $constructorArguments)
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']