‪TYPO3CMS  9.5
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  */
16 use Doctrine\DBAL\Driver\Statement;
17 use Prophecy\Argument;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪ExtendedFileUtilityTest extends UnitTestCase
31 {
35  protected function ‪setUp()
36  {
37  ‪$GLOBALS['LANG'] = $this->getMockBuilder(\‪TYPO3\CMS\Core\Localization\LanguageService::class)
38  ->setMethods(['sL'])
39  ->getMock();
40  }
41 
46  {
47  $fileUid = 1;
48  $file = $this->getMockBuilder(File::class)
49  ->setMethods(['getUid'])
50  ->disableOriginalConstructor()
51  ->getMock();
52  $file->expects($this->once())->method('getUid')->will($this->returnValue($fileUid));
53 
54  $folder = $this->getMockBuilder(Folder::class)
55  ->setMethods(['getFiles'])
56  ->disableOriginalConstructor()
57  ->getMock();
58  $folder->expects($this->once())
59  ->method('getFiles')->with(0, 0, ‪Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true)
60  ->will(
61  $this->returnValue([$file])
62  );
63 
65  $subject = $this->getMockBuilder(\‪TYPO3\CMS\Core\Utility\‪File\ExtendedFileUtility::class)
66  ->setMethods(['addFlashMessage'])
67  ->getMock();
68 
69  // prophetizing the DB query
70  $expressionBuilderProphet = $this->prophesize(ExpressionBuilder::class);
71  $expressionBuilderProphet->eq(Argument::cetera())->willReturn('1 = 1');
72  $expressionBuilderProphet->neq(Argument::cetera())->willReturn('1 != 1');
73  $expressionBuilderProphet->in(Argument::cetera())->willReturn('uid IN (1)');
74  $databaseStatementProphet = $this->prophesize(Statement::class);
75  $databaseStatementProphet->fetchColumn(Argument::cetera())->willReturn(1);
76  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
77  $queryBuilderProphet->getRestrictions()->willReturn(GeneralUtility::makeInstance(DefaultRestrictionContainer::class));
78  $queryBuilderProphet->count(Argument::cetera())->willReturn($queryBuilderProphet);
79  $queryBuilderProphet->from(Argument::cetera())->willReturn($queryBuilderProphet);
80  $queryBuilderProphet->where(Argument::cetera())->willReturn($queryBuilderProphet);
81  $queryBuilderProphet->createNamedParameter(Argument::cetera())->willReturn(Argument::type('string'));
82  $queryBuilderProphet->execute()->willReturn($databaseStatementProphet);
83  $queryBuilderProphet->expr()->willReturn($expressionBuilderProphet->reveal());
84  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
85  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
86  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
87 
88  ‪$GLOBALS['LANG']->expects($this->at(0))->method('sL')
89  ->with('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:message.description.folderNotDeletedHasFilesWithReferences')
90  ->will($this->returnValue('folderNotDeletedHasFilesWithReferences'));
91  ‪$GLOBALS['LANG']->expects($this->at(1))->method('sL')
92  ->with('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:message.header.folderNotDeletedHasFilesWithReferences')
93  ->will($this->returnValue('folderNotDeletedHasFilesWithReferences'));
94 
95  $result = $subject->folderHasFilesInUse($folder);
96  $this->assertTrue($result);
97  }
98 
103  {
104  $folder = $this->getMockBuilder(Folder::class)
105  ->setMethods(['getFiles'])
106  ->disableOriginalConstructor()
107  ->getMock();
108  $folder->expects($this->once())->method('getFiles')->with(0, 0, ‪Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true)->will(
109  $this->returnValue([])
110  );
111 
113  $subject = $this->getMockBuilder(\‪TYPO3\CMS\Core\Utility\‪File\ExtendedFileUtility::class)
114  ->setMethods(['addFlashMessage'])
115  ->getMock();
116  $this->assertFalse($subject->folderHasFilesInUse($folder));
117  }
118 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3
‪TYPO3\CMS\Core\Resource\Folder\FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
‪const FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
Definition: Folder.php:66
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Core\Tests\Unit\Utility\File\ExtendedFileUtilityTest\folderHasFilesInUseReturnsTrueIfItHasFiles
‪folderHasFilesInUseReturnsTrueIfItHasFiles()
Definition: ExtendedFileUtilityTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Utility\File
Definition: ExtendedFileUtilityTest.php:2
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Tests\Unit\Utility\File\ExtendedFileUtilityTest
Definition: ExtendedFileUtilityTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Utility\File\ExtendedFileUtilityTest\setUp
‪setUp()
Definition: ExtendedFileUtilityTest.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Utility\File\ExtendedFileUtilityTest\folderHasFilesInUseReturnsFalseIfItHasNoFiles
‪folderHasFilesInUseReturnsFalseIfItHasNoFiles()
Definition: ExtendedFileUtilityTest.php:102
‪TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer
Definition: DefaultRestrictionContainer.php:22