TYPO3 CMS  TYPO3_6-2
PageRepositoryTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $pageSelectObject;
28 
32  public function setUp() {
33  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
34  $this->pageSelectObject = $this->getAccessibleMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('getMultipleGroupsWhereClause'));
35  $this->pageSelectObject->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
36  }
37 
43  public function isGetPageHookCalled() {
44  // Create a hook mock object
45  $className = $this->getUniqueId('tx_coretest');
46  $getPageHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepositoryGetPageHookInterface', array('getPage_preProcess'), array(), $className);
47  // Register hook mock object
48  $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
49  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
50  // Test if hook is called and register a callback method to check given arguments
51  $getPageHookMock->expects($this->once())->method('getPage_preProcess')->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
52  $this->pageSelectObject->getPage(42, FALSE);
53  }
54 
59  list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
60  $this->assertEquals(42, $uid);
61  $this->assertFalse($disableGroupAccessCheck);
62  $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\Page\PageRepository);
63  }
64 
66  // Tests concerning getPathFromRootline
68 
72  $this->assertEquals('', $this->pageSelectObject->getPathFromRootline(array()));
73  }
74 
76  // Tests concerning getExtURL
78 
82  $this->assertEquals('http://www.example.com', $this->pageSelectObject->getExtURL(array(
83  'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
84  'urltype' => 1,
85  'url' => 'www.example.com'
86  )));
87  }
88 
93  $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/', $this->pageSelectObject->getExtURL(array(
94  'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
95  'urltype' => 0,
96  'url' => 'hello/world/'
97  )));
98  }
99 
101  // Tests concerning shouldFieldBeOverlaid
103 
107  public function shouldFieldBeOverlaid($field, $table, $value, $expected, $comment = '') {
108  $GLOBALS['TCA']['fake_table']['columns'] = array(
109  'exclude' => array(
110  'l10n_mode' => 'exclude',
111  'config' => array('type' => 'input'),
112  ),
113  'mergeIfNotBlank' => array(
114  'l10n_mode' => 'mergeIfNotBlank',
115  'config' => array('type' => 'input'),
116  ),
117  'mergeIfNotBlank_group' => array(
118  'l10n_mode' => 'mergeIfNotBlank',
119  'config' => array('type' => 'group'),
120  ),
121  'default' => array(
122  // no l10n_mode set
123  'config' => array('type' => 'input'),
124  ),
125  'noCopy' => array(
126  'l10n_mode' => 'noCopy',
127  'config' => array('type' => 'input'),
128  ),
129  'prefixLangTitle' => array(
130  'l10n_mode' => 'prefixLangTitle',
131  'config' => array('type' => 'input'),
132  ),
133  );
134 
135  $result = $this->pageSelectObject->_call('shouldFieldBeOverlaid', $table, $field, $value);
136  unset($GLOBALS['TCA']['fake_table']);
137 
138  $this->assertSame($expected, $result, $comment);
139  }
140 
144  public function getShouldFieldBeOverlaidData() {
145  return array(
146  array('default', 'fake_table', 'foobar', TRUE, 'default is to merge non-empty string'),
147  array('default', 'fake_table', '', TRUE, 'default is to merge empty string'),
148 
149  array('exclude', 'fake_table', '', FALSE, 'exclude field with empty string'),
150  array('exclude', 'fake_table', 'foobar', FALSE, 'exclude field with non-empty string'),
151 
152  array('mergeIfNotBlank', 'fake_table', '', FALSE, 'mergeIfNotBlank is not merged with empty string'),
153  array('mergeIfNotBlank', 'fake_table', 0, TRUE, 'mergeIfNotBlank is merged with 0'),
154  array('mergeIfNotBlank', 'fake_table', '0', TRUE, 'mergeIfNotBlank is merged with "0"'),
155  array('mergeIfNotBlank', 'fake_table', 'foobar', TRUE, 'mergeIfNotBlank is merged with non-empty string'),
156 
157  array('mergeIfNotBlank_group', 'fake_table', '', FALSE, 'mergeIfNotBlank on group is not merged empty string'),
158  array('mergeIfNotBlank_group', 'fake_table', 0, FALSE, 'mergeIfNotBlank on group is not merged with 0'),
159  array('mergeIfNotBlank_group', 'fake_table', '0', FALSE, 'mergeIfNotBlank on group is not merged with "0"'),
160  array('mergeIfNotBlank_group', 'fake_table', 'foobar', TRUE, 'mergeIfNotBlank on group is merged with non-empty string'),
161 
162  array('noCopy', 'fake_table', 'foobar', TRUE, 'noCopy is merged with non-empty string'),
163  array('noCopy', 'fake_table', '', TRUE, 'noCopy is merged with empty string'),
164 
165  array('prefixLangTitle', 'fake_table', 'foobar', TRUE, 'prefixLangTitle is merged with non-empty string'),
166  array('prefixLangTitle', 'fake_table', '', TRUE, 'prefixLangTitle is merged with empty string'),
167  );
168  }
169 
171  // Tests concerning workspaces
173 
178  // initialization
179  $wsid = 987654321;
180 
181  // simulate calls from tslib_fe->fetch_the_id()
182  $this->pageSelectObject->versioningPreview = FALSE;
183  $this->pageSelectObject->versioningWorkspaceId = $wsid;
184  $this->pageSelectObject->init(FALSE);
185 
186  // check SQL created by t3lib_pageSelect->getPage()
187  $GLOBALS['TYPO3_DB']->expects($this->once())
188  ->method('exec_SELECTquery')
189  ->with(
190  '*',
191  'pages',
192  $this->logicalAnd(
193  $this->logicalNot(
194  $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
195  ),
196  $this->stringContains('AND NOT pages.t3ver_state>0')
197  )
198  );
199 
200  $this->pageSelectObject->getPage(1);
201 
202  }
203 
208  // initialization
209  $wsid = 987654321;
210 
211  // simulate calls from tslib_fe->fetch_the_id()
212  $this->pageSelectObject->versioningPreview = TRUE;
213  $this->pageSelectObject->versioningWorkspaceId = $wsid;
214  $this->pageSelectObject->init(FALSE);
215 
216  // check SQL created by t3lib_pageSelect->getPage()
217  $GLOBALS['TYPO3_DB']->expects($this->once())
218  ->method('exec_SELECTquery')
219  ->with(
220  '*',
221  'pages',
222  $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
223  );
224 
225  $this->pageSelectObject->getPage(1);
226 
227  }
228 
230  // Tests concerning versioning
232 
237  $table = $this->getUniqueId('aTable');
238  $GLOBALS['TCA'] = array(
239  $table => array(
240  'ctrl' => array(
241  'versioningWS' => 2
242  )
243  )
244  );
245 
246  $this->pageSelectObject->versioningPreview = FALSE;
247  $this->pageSelectObject->init(FALSE);
248 
249  $conditions = $this->pageSelectObject->enableFields($table);
250 
251  $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.t3ver_state<=0'), 'Versioning placeholders');
252  $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
253  }
254 
259  $table = $this->getUniqueId('aTable');
260  $GLOBALS['TCA'] = array(
261  $table => array(
262  'ctrl' => array(
263  'versioningWS' => 2
264  )
265  )
266  );
267 
268  $this->pageSelectObject->versioningPreview = TRUE;
269  $this->pageSelectObject->init(FALSE);
270 
271  $conditions = $this->pageSelectObject->enableFields($table);
272 
273  $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
274  $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
275  }
276 
281  $table = $this->getUniqueId('aTable');
282  $GLOBALS['TCA'] = array(
283  $table => array(
284  'ctrl' => array(
285  'versioningWS' => 2
286  )
287  )
288  );
289 
290  $this->pageSelectObject->versioningPreview = TRUE;
291  $this->pageSelectObject->versioningWorkspaceId = 2;
292  $this->pageSelectObject->init(FALSE);
293 
294  $conditions = $this->pageSelectObject->enableFields($table);
295 
296  $this->assertThat($conditions, $this->stringContains(' AND (' . $table . '.t3ver_wsid=0 OR ' . $table . '.t3ver_wsid=2)'), 'No versioning placeholders');
297  }
298 
303  $table = $this->getUniqueId('aTable');
304  $GLOBALS['TCA'] = array(
305  $table => array(
306  'ctrl' => array(
307  'versioningWS' => 2
308  )
309  )
310  );
311 
312  $this->pageSelectObject->versioningPreview = TRUE;
313  $this->pageSelectObject->init(FALSE);
314 
315  $conditions = $this->pageSelectObject->enableFields($table, -1, array(), TRUE );
316 
317  $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
318  $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.pid<>-1')), 'No ecords from page -1');
319  }
320 
321 
322 }
$uid
Definition: server.php:36
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.
shouldFieldBeOverlaid($field, $table, $value, $expected, $comment='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]