TYPO3 CMS  TYPO3_6-2
FolderTest.php
Go to the documentation of this file.
1 <?php
3 
17 use \org\bovigo\vfs\vfsStream;
18 
25 
29  protected $singletonInstances = array();
30 
31  protected $basedir = 'basedir';
32 
33  public function setUp() {
35  vfsStream::setup($this->basedir);
36  }
37 
38  protected function tearDown() {
40  parent::tearDown();
41  }
42 
43  protected function createFolderFixture($path, $name, $mockedStorage = NULL) {
44  if ($mockedStorage === NULL) {
45  $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
46  }
47  return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $path, $name, 0);
48  }
49 
54  $path = $this->getUniqueId();
55  $name = $this->getUniqueId();
56  $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
57  $fixture = $this->createFolderFixture($path, $name, $mockedStorage);
58  $this->assertSame($mockedStorage, $fixture->getStorage());
59  $this->assertStringStartsWith($path, $fixture->getIdentifier());
60  $this->assertSame($name, $fixture->getName());
61  }
62 
66  public function propertiesCanBeUpdated() {
67  $fixture = $this->createFolderFixture('/somePath', 'someName');
68  $fixture->updateProperties(array('identifier' => '/someOtherPath', 'name' => 'someNewName'));
69  $this->assertSame('someNewName', $fixture->getName());
70  $this->assertSame('/someOtherPath', $fixture->getIdentifier());
71  }
72 
77  $fixture = $this->createFolderFixture('/somePath/someName/', 'someName');
78  $fixture->updateProperties(array('identifier' => '/someOtherPath'));
79  $this->assertSame('someName', $fixture->getName());
80  }
81 
86  $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
87  $mockedStorage->expects($this->once())->method('getFilesInFolder')->will($this->returnValue(array(
88  'somefile.png' => array(
89  'name' => 'somefile.png'
90  ),
91  'somefile.jpg' => array(
92  'name' => 'somefile.jpg'
93  )
94  )
95  ));
96  $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
97 
98  $fileList = $fixture->getFiles();
99 
100  $this->assertSame(array('somefile.png', 'somefile.jpg'), array_keys($fileList));
101  }
102 
107  $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
108  $mockedStorage
109  ->expects($this->once())
110  ->method('getFilesInFolder')
111  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), FALSE)
112  ->will($this->returnValue(array()));
113 
114  $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
115  $fixture->getFiles();
116  }
117 
122  $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
123  $mockedStorage
124  ->expects($this->once())
125  ->method('getFilesInFolder')
126  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), TRUE)
127  ->will($this->returnValue(array()));
128 
129  $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
130  $fixture->getFiles(0, 0, \TYPO3\CMS\Core\Resource\Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, TRUE);
131  }
132 
137  $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
138  $mockedStorage->expects($this->once())->method('hasFolderInFolder')->with($this->equalTo('someSubfolder'))->will($this->returnValue(TRUE));
139  $mockedFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
140  $mockedFactory->expects($this->once())->method('createFolderObject')->with($mockedStorage, '/somePath/someFolder/someSubfolder/', 'someSubfolder');
141  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedFactory);
142  $fixture = $this->createFolderFixture('/somePath/someFolder/', 'someFolder', $mockedStorage);
143  $fixture->getSubfolder('someSubfolder');
144  }
145 
150  $parentIdentifier = '/parent/';
151  $currentIdentifier = '/parent/current/';
152 
153  $parentFolderFixture = $this->createFolderFixture($parentIdentifier, 'parent');
154  $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFolderIdentifierFromFileIdentifier', 'getFolder'), array(), '', FALSE);
155  $mockedStorage->expects($this->once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->will($this->returnValue($parentIdentifier));
156  $mockedStorage->expects($this->once())->method('getFolder')->with($parentIdentifier)->will($this->returnValue($parentFolderFixture));
157 
158  $currentFolderFixture = $this->createFolderFixture($currentIdentifier, 'current', $mockedStorage);
159 
160  $this->assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder());
161  }
162 }
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
const FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
Definition: Folder.php:71
createFolderFixture($path, $name, $mockedStorage=NULL)
Definition: FolderTest.php:43