2 declare(strict_types = 1);
17 use Doctrine\DBAL\Driver\Statement;
18 use Prophecy\Argument;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
44 protected function setUp()
46 $proxyClassName = $this->buildAccessibleProxy(AbstractMenuContentObject::class);
47 $this->subject = $this->getMockForAbstractClass($proxyClassName);
48 $GLOBALS[
'TSFE'] = $this->getMockBuilder(\
TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class)
49 ->setConstructorArgs([
$GLOBALS[
'TYPO3_CONF_VARS'], 1, 1])
50 ->setMethods([
'initCaches'])
61 GeneralUtility::purgeInstances();
73 $connectionProphet = $this->prophesize(Connection::class);
74 $connectionProphet->getExpressionBuilder()->willReturn(
new ExpressionBuilder($connectionProphet->reveal()));
75 $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
77 $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
78 $connectionPoolProphet->getConnectionForTable(
'tt_content')->willReturn($connectionProphet->reveal());
79 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
88 $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
89 $pageRepository->expects($this->once())->method(
'getPage')->will($this->returnValue(
null));
90 $this->subject->_set(
'sys_page', $pageRepository);
91 $result = $this->subject->_call(
'sectionIndex',
'field');
92 $this->assertEquals($result, []);
101 $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
102 $pageRepository->expects($this->once())->method(
'getPage')->will($this->returnValue(
null))->with(10);
103 $this->subject->_set(
'sys_page', $pageRepository);
104 $this->subject->_set(
'id', 10);
105 $result = $this->subject->_call(
'sectionIndex',
'field');
106 $this->assertEquals($result, []);
114 $this->expectException(\UnexpectedValueException::class);
115 $this->expectExceptionCode(1337334849);
117 $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
118 $pageRepository->expects($this->once())->method(
'getPage')->will($this->returnValue([]));
119 $this->subject->_set(
'sys_page', $pageRepository);
120 $this->subject->_set(
'id', 10);
122 $cObject = $this->getMockBuilder(ContentObjectRenderer::class)->getMock();
123 $cObject->expects($this->once())->method(
'exec_getQuery')->will($this->returnValue(0));
124 $this->subject->_set(
'parent_cObj', $cObject);
126 $this->subject->_call(
'sectionIndex',
'field');
134 $statementProphet = $this->prophesize(Statement::class);
135 $statementProphet->fetch()->shouldBeCalledTimes(2)->willReturn([
'uid' => 0,
'header' =>
'NOT_OVERLAID'],
false);
138 $this->subject->_set(
'mconf', [
143 $context = GeneralUtility::makeInstance(Context::class);
146 $pageRepository = $this->getMockBuilder(PageRepository::class)->setConstructorArgs([$context])->getMock();
147 $pageRepository->expects($this->once())->method(
'getPage')->will($this->returnValue([
'_PAGES_OVERLAY_LANGUAGE' => 1]));
148 $pageRepository->expects($this->once())->method(
'getRecordOverlay')->will($this->returnValue([
'uid' => 0,
'header' =>
'OVERLAID']));
149 $this->subject->_set(
'sys_page', $pageRepository);
151 $cObject = $this->getMockBuilder(ContentObjectRenderer::class)->getMock();
152 $cObject->expects($this->once())->method(
'exec_getQuery')->willReturn($statementProphet->reveal());
153 $this->subject->_set(
'parent_cObj', $cObject);
155 $result = $this->subject->_call(
'sectionIndex',
'field');
156 $this->assertEquals($result[0][
'title'],
'OVERLAID');
165 'unfiltered fields' => [
173 'with unset section index' => [
181 'with unset header' => [
189 'with header layout 100' => [
194 'header_layout' => 100
208 $statementProphet = $this->prophesize(Statement::class);
209 $statementProphet->fetch()->willReturn($dataRow,
false);
212 $this->subject->_set(
'mconf', [
218 $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
219 $pageRepository->expects($this->once())->method(
'getPage')->will($this->returnValue([
'_PAGES_OVERLAY_LANGUAGE' => 1]));
220 $pageRepository->expects($this->once())->method(
'getPage')->will($this->returnValue([]));
221 $this->subject->_set(
'sys_page', $pageRepository);
223 $cObject = $this->getMockBuilder(ContentObjectRenderer::class)->getMock();
224 $cObject->expects($this->once())->method(
'exec_getQuery')->willReturn($statementProphet->reveal());
225 $this->subject->_set(
'parent_cObj', $cObject);
227 $result = $this->subject->_call(
'sectionIndex',
'field');
228 $this->assertCount($expectedAmount, $result);
237 'no configuration' => [
241 'with useColPos 2' => [
245 'with useColPos -1' => [
249 'with stdWrap useColPos' => [
268 $statementProphet = $this->prophesize(Statement::class);
269 $statementProphet->fetch()->willReturn([]);
272 $this->subject->_set(
'mconf', [
'sectionIndex.' => $configuration]);
274 $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
275 $pageRepository->expects($this->once())->method(
'getPage')->will($this->returnValue([]));
276 $this->subject->_set(
'sys_page', $pageRepository);
278 $queryConfiguration = [
280 'orderBy' =>
'field',
281 'languageField' =>
'sys_language_uid',
282 'where' => $whereClausePrefix
285 $cObject = $this->getMockBuilder(ContentObjectRenderer::class)->getMock();
286 $cObject->expects($this->once())->method(
'exec_getQuery')
287 ->with(
'tt_content', $queryConfiguration)->willReturn($statementProphet->reveal());
288 $this->subject->_set(
'parent_cObj', $cObject);
290 $this->subject->_call(
'sectionIndex',
'field', 12);
312 'three excluded' => [
317 'empty excludeList' => [
340 foreach ($menuItems as $page) {
341 $menu[] = [
'uid' => $page];
343 $runtimeCacheMock = $this->getMockBuilder(VariableFrontend::class)->setMethods([
'get',
'set'])->disableOriginalConstructor()->getMock();
344 $runtimeCacheMock->expects($this->once())->method(
'get')->with($this->anything())->willReturn(
false);
345 $runtimeCacheMock->expects($this->once())->method(
'set')->with($this->anything(), [
'result' => $expectedResult]);
347 $proxyClassName = $this->buildAccessibleProxy(AbstractMenuContentObject::class);
348 $this->subject = $this->getMockForAbstractClass($proxyClassName, [],
'',
true,
true,
true, [
'getRuntimeCache']);
349 $this->subject->expects($this->once())->method(
'getRuntimeCache')->willReturn($runtimeCacheMock);
352 $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
353 $pageRepository->expects($this->once())->method(
'getMenu')->will($this->returnValue($menu));
354 $this->subject->_set(
'sys_page', $pageRepository);
355 $this->subject->_set(
'menuArr', [
358 $this->subject->_set(
'conf', [
'excludeUidList' => $excludeUidList]);
360 $this->assertEquals($expectedResult, $this->subject->_call(
'isItemState',
'IFSUB', 0));
369 'standard parameter without access protected setting' => [
372 'linkAccessRestrictedPages' =>
false,
373 'useCacheHash' => true
376 'showAccessRestrictedPages' => false
387 'standard parameter with access protected setting' => [
390 'linkAccessRestrictedPages' =>
true,
391 'useCacheHash' => true
394 'showAccessRestrictedPages' => true
405 'standard parameter with access protected setting "NONE" casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
408 'linkAccessRestrictedPages' =>
true,
409 'useCacheHash' => true
412 'showAccessRestrictedPages' =>
'NONE'
423 'standard parameter with access protected setting (int)67 casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
426 'linkAccessRestrictedPages' =>
true,
427 'useCacheHash' => true
430 'showAccessRestrictedPages' => 67
441 'standard parameter with target' => [
444 'target' =>
'_blank',
445 'linkAccessRestrictedPages' =>
false,
446 'useCacheHash' => true
449 'showAccessRestrictedPages' => false
460 'parameter with typeOverride=10' => [
462 'parameter' =>
'10,10',
463 'linkAccessRestrictedPages' =>
false,
464 'useCacheHash' => true
467 'showAccessRestrictedPages' => false
478 'parameter with target and typeOverride=10' => [
480 'parameter' =>
'10,10',
481 'linkAccessRestrictedPages' =>
false,
482 'useCacheHash' =>
true,
486 'showAccessRestrictedPages' => false
497 'parameter with invalid value in typeOverride=foobar ignores typeOverride' => [
500 'linkAccessRestrictedPages' =>
false,
501 'useCacheHash' =>
true,
505 'showAccessRestrictedPages' => false
516 'standard parameter with section name' => [
519 'target' =>
'_blank',
520 'linkAccessRestrictedPages' =>
false,
522 'section' =>
'section-name'
525 'showAccessRestrictedPages' => false
530 'sectionIndex_uid' =>
'section-name'
539 'standard parameter with additional parameters' => [
542 'linkAccessRestrictedPages' =>
false,
544 'section' =>
'section-name',
545 'additionalParams' =>
'&test=foobar'
548 'showAccessRestrictedPages' => false
553 'sectionIndex_uid' =>
'section-name'
562 'overridden page array uid value gets used as parameter' => [
565 'linkAccessRestrictedPages' =>
false,
567 'section' =>
'section-name'
570 'showAccessRestrictedPages' => false
575 'sectionIndex_uid' =>
'section-name'
603 $cObject = $this->getMockBuilder(ContentObjectRenderer::class)
604 ->setMethods([
'typoLink'])
606 $cObject->expects($this->once())->method(
'typoLink')->with(
'|', $expected);
607 $this->subject->_set(
'parent_cObj', $cObject);
608 $this->subject->_set(
'mconf', $mconf);
609 $this->subject->_set(
'useCacheHash', $useCacheHash);
610 $this->subject->_call(
'menuTypoLink', $page, $oTarget, $no_cache, $script, $overrideArray, $addParams, $typeOverride);