PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/sysext/core/Tests/Unit/Resource/FactoryTest.php

https://github.com/netactive/typo3
PHP | 143 lines | 65 code | 16 blank | 62 comment | 0 complexity | 7618a5ef9615777499ea9071dbcf4eee MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.1, LGPL-3.0, Apache-2.0
  1. <?php
  2. namespace TYPO3\CMS\Core\Tests\Unit\Resource;
  3. /***************************************************************
  4. * Copyright notice
  5. *
  6. * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
  7. * All rights reserved
  8. *
  9. * This script is part of the TYPO3 project. The TYPO3 project is
  10. * free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * The GNU General Public License can be found at
  16. * http://www.gnu.org/copyleft/gpl.html.
  17. *
  18. * This script is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * This copyright notice MUST APPEAR in all copies of the script!
  24. ***************************************************************/
  25. require_once 'vfsStream/vfsStream.php';
  26. /**
  27. * Testcase for the factory of FAL
  28. *
  29. * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
  30. */
  31. class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
  32. /**
  33. * @var array A backup of registered singleton instances
  34. */
  35. protected $singletonInstances = array();
  36. /**
  37. * @var \TYPO3\CMS\Core\Resource\ResourceFactory
  38. */
  39. private $fixture;
  40. /**
  41. * @var boolean
  42. */
  43. private $objectCreated = FALSE;
  44. /**
  45. * @var array
  46. */
  47. private $filesCreated = array();
  48. public function setUp() {
  49. $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
  50. $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array('dummy'));
  51. }
  52. public function tearDown() {
  53. \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
  54. foreach ($this->filesCreated as $file) {
  55. unlink($file);
  56. }
  57. }
  58. /**********************************
  59. * Storage Collections
  60. **********************************/
  61. /**
  62. * @test
  63. */
  64. public function createStorageCollectionObjectCreatesCollectionWithCorrectArguments() {
  65. $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
  66. $path = uniqid();
  67. $name = uniqid();
  68. $storageCollection = $this->fixture->createFolderObject($mockedMount, $path, $name, 0);
  69. $this->assertSame($mockedMount, $storageCollection->getStorage());
  70. $this->assertEquals($path . '/', $storageCollection->getIdentifier());
  71. $this->assertEquals($name, $storageCollection->getName());
  72. }
  73. /**********************************
  74. * Drivers
  75. **********************************/
  76. /**
  77. * @test
  78. */
  79. public function getDriverObjectAcceptsDriverClassName() {
  80. $mockedDriver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), array(), '', FALSE);
  81. $driverFixtureClass = get_class($mockedDriver);
  82. \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($driverFixtureClass, $mockedDriver);
  83. $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
  84. $mockedRegistry = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry');
  85. $mockedRegistry->expects($this->once())->method('getDriverClass')->with($this->equalTo($driverFixtureClass))->will($this->returnValue($driverFixtureClass));
  86. \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry', $mockedRegistry);
  87. $obj = $this->fixture->getDriverObject($driverFixtureClass, array());
  88. $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', $obj);
  89. }
  90. /***********************************
  91. * File Handling
  92. ***********************************/
  93. public function directoryDataProviderValidFolderValues() {
  94. return array(
  95. 'relative path' => array('fileadmin'),
  96. 'path with PATH_site' => array(PATH_site . 'fileadmin')
  97. );
  98. }
  99. /**
  100. * @test
  101. * @dataProvider directoryDataProviderValidFolderValues
  102. */
  103. public function retrieveFileOrFolderObjectReturnsFolderIfPathIsGiven($source) {
  104. $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
  105. $storage->expects($this->once())
  106. ->method('getFolder')
  107. ->with('fileadmin');
  108. $this->fixture->_set('storageInstances', array(0 => $storage));
  109. $this->fixture->retrieveFileOrFolderObject($source);
  110. }
  111. /**
  112. * @test
  113. */
  114. public function retrieveFileOrFolderObjectReturnsFileIfPathIsGiven() {
  115. $filename = 'typo3temp/4711.txt';
  116. $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
  117. $storage->expects($this->once())
  118. ->method('getFile')
  119. ->with($filename);
  120. $this->fixture->_set('storageInstances', array(0 => $storage));
  121. // Create and prepare test file
  122. \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filename, '42');
  123. $this->filesCreated[] = PATH_site . $filename;
  124. $this->fixture->retrieveFileOrFolderObject($filename);
  125. }
  126. }
  127. ?>