TYPO3 CMS  TYPO3_6-2
FileControllerTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $fileController;
26 
30  protected $fileResourceMock;
31 
36 
40  protected $mockFileProcessor;
41 
46 
50  protected function setUp() {
51  $this->fileResourceMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array('toArray', 'getModificationTime', 'getExtension'), array(), '', FALSE);
52  $this->folderResourceMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array('getIdentifier'), array(), '', FALSE);
53  $this->mockFileProcessor = $this->getMock('TYPO3\\CMS\\Core\\Utility\\File\ExtendedFileUtility', array('getErrorMessages'), array(), '', FALSE);
54 
55  $this->fileResourceMock->expects($this->any())->method('toArray')->will($this->returnValue(array('id' => 'foo')));
56  $this->fileResourceMock->expects($this->any())->method('getModificationTime')->will($this->returnValue(123456789));
57  $this->fileResourceMock->expects($this->any())->method('getExtension')->will($this->returnValue('html'));
58  }
59 
64  $this->fileController = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Controller\\File\\FileController', array('dummy'));
65 
66  $this->folderResourceMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('bar'));
67 
68  $this->mockFileProcessor->expects($this->any())->method('getErrorMessages')->will($this->returnValue(array()));
69 
70  $this->assertTrue($this->fileController->_call('flattenResultDataValue', TRUE));
71  $this->assertSame(array(), $this->fileController->_call('flattenResultDataValue', array()));
72 
73  $this->assertSame(
74  array(
75  'id' => 'foo',
76  'date' => '29-11-73',
77  'iconClasses' => 't3-icon t3-icon-mimetypes t3-icon-mimetypes-text t3-icon-text-html'
78  ),
79  $this->fileController->_call('flattenResultDataValue', $this->fileResourceMock)
80  );
81 
82  $this->assertSame(
83  'bar',
84  $this->fileController->_call('flattenResultDataValue', $this->folderResourceMock)
85  );
86  }
87 
92  $this->fileController = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Controller\\File\\FileController', array('init', 'main'));
93  $this->mockAjaxRequestHandler = $this->getMock('TYPO3\\CMS\\Core\\Http\\AjaxRequestHandler', array('addContent', 'setContentFormat'), array(), '', FALSE);
94 
95  $fileData = array('delete' => array(TRUE));
96  $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
97  $this->fileController->_set('fileData', $fileData);
98  $this->fileController->_set('redirect', FALSE);
99 
100  $this->fileController->expects($this->once())->method('init');
101  $this->fileController->expects($this->once())->method('main');
102  $this->mockAjaxRequestHandler->expects($this->once())->method('addContent')->with('result', $fileData);
103  $this->mockAjaxRequestHandler->expects($this->once())->method('setContentFormat')->with('json');
104 
105  $this->fileController->processAjaxRequest(array(), $this->mockAjaxRequestHandler);
106  }
107 
112  $this->fileController = $this->getAccessibleMock('TYPO3\CMS\\Backend\\Controller\\File\\FileController', array('init', 'main'));
113  $this->mockAjaxRequestHandler = $this->getMock('TYPO3\\CMS\\Core\\Http\\AjaxRequestHandler', array('addContent', 'setContentFormat'), array(), '', FALSE);
114 
115  $fileData = array('editfile' => array(TRUE));
116  $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
117  $this->fileController->_set('fileData', $fileData);
118  $this->fileController->_set('redirect', FALSE);
119 
120  $this->fileController->expects($this->once())->method('init');
121  $this->fileController->expects($this->once())->method('main');
122  $this->mockAjaxRequestHandler->expects($this->once())->method('addContent')->with('result', $fileData);
123  $this->mockAjaxRequestHandler->expects($this->once())->method('setContentFormat')->with('json');
124 
125  $this->fileController->processAjaxRequest(array(), $this->mockAjaxRequestHandler);
126  }
127 
132  $this->fileController = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Controller\\File\\FileController', array('init', 'main'));
133  $this->mockAjaxRequestHandler = $this->getMock('TYPO3\\CMS\\Core\\Http\\AjaxRequestHandler', array('addContent', 'setContentFormat'), array(), '', FALSE);
134 
135  $fileData = array('unzip' => array(TRUE));
136  $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
137  $this->fileController->_set('fileData', $fileData);
138  $this->fileController->_set('redirect', FALSE);
139 
140  $this->fileController->expects($this->once())->method('init');
141  $this->fileController->expects($this->once())->method('main');
142  $this->mockAjaxRequestHandler->expects($this->once())->method('addContent')->with('result', $fileData);
143  $this->mockAjaxRequestHandler->expects($this->once())->method('setContentFormat')->with('json');
144 
145  $this->fileController->processAjaxRequest(array(), $this->mockAjaxRequestHandler);
146  }
147 
152  $this->fileController = $this->getAccessibleMock('TYPO3\\CMS\Backend\\Controller\\File\\FileController', array('init', 'main'));
153  $this->mockAjaxRequestHandler = $this->getMock('TYPO3\\CMS\\Core\\Http\\AjaxRequestHandler', array('addContent', 'setContentFormat'), array(), '', FALSE);
154 
155  $fileData = array('upload' => array(array($this->fileResourceMock)));
156  $result = array('upload' => array(array(
157  'id' => 'foo',
158  'date' => '29-11-73',
159  'iconClasses' => 't3-icon t3-icon-mimetypes t3-icon-mimetypes-text t3-icon-text-html'
160  )));
161  $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
162  $this->fileController->_set('fileData', $fileData);
163  $this->fileController->_set('redirect', FALSE);
164 
165  $this->fileController->expects($this->once())->method('init');
166  $this->fileController->expects($this->once())->method('main');
167  $this->mockAjaxRequestHandler->expects($this->once())->method('addContent')->with('result', $result);
168  $this->mockAjaxRequestHandler->expects($this->once())->method('setContentFormat')->with('json');
169 
170  $this->fileController->processAjaxRequest(array(), $this->mockAjaxRequestHandler);
171  }
172 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.