2 declare(strict_types = 1);
19 use Prophecy\Argument;
20 use Prophecy\Prophecy\ObjectProphecy;
25 use TYPO3\CMS\Core\Package\PackageManager;
30 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
61 protected function setUp(): void
65 $this->packageManagerProphecy = $this->prophesize(PackageManager::class);
67 $this->templateServiceMock = $this->getAccessibleMock(
68 TemplateService::class,
70 [
new Context(), $this->packageManagerProphecy->reveal()]
89 $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
90 $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
91 $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
92 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
94 $this->packageManagerProphecy->getActivePackages()->shouldNotBeCalled();
96 $this->templateService->runThroughTemplates([], 0);
98 in_array(
'test.Core.TypoScript = 1', $this->templateService->config,
true)
107 $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
108 $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
109 $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
110 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
112 $mockPackage = $this->getMockBuilder(Package::class)
113 ->setMethods([
'getPackagePath',
'getPackageKey'])
114 ->disableOriginalConstructor()
116 $mockPackage->expects($this->any())->method(
'getPackagePath')->will($this->returnValue(__DIR__ .
'/Fixtures/'));
117 $mockPackage->expects($this->any())->method(
'getPackageKey')->will($this->returnValue(
'core'));
119 $mockPackageManager = $this->getMockBuilder(PackageManager::class)
120 ->setMethods([
'isPackageActive',
'getPackage'])
121 ->disableOriginalConstructor()
123 $mockPackageManager->expects($this->any())->method(
'isPackageActive')->will($this->returnValue(
true));
124 $mockPackageManager->expects($this->any())->method(
'getPackage')->will($this->returnValue($mockPackage));
126 $this->packageManagerProphecy->getActivePackages()->willReturn([
'core' => $mockPackage]);
128 $this->templateService->setProcessExtensionStatics(
true);
129 $this->templateService->runThroughTemplates([], 0);
132 in_array(
'test.Core.TypoScript = 1', $this->templateService->config,
true)
141 $originalRootline = [
142 0 => [
'uid' => 2,
'title' =>
'originalTitle'],
143 1 => [
'uid' => 3,
'title' =>
'originalTitle2'],
147 0 => [
'uid' => 1,
'title' =>
'newTitle'],
148 1 => [
'uid' => 2,
'title' =>
'newTitle2'],
149 2 => [
'uid' => 3,
'title' =>
'newTitle3'],
152 $expectedRootline = [
153 0 => [
'uid' => 2,
'title' =>
'newTitle2'],
154 1 => [
'uid' => 3,
'title' =>
'newTitle3'],
157 $this->templateServiceMock->_set(
'rootLine', $originalRootline);
158 $this->templateServiceMock->updateRootlineData($updatedRootline);
159 $this->assertEquals($expectedRootline, $this->templateServiceMock->_get(
'rootLine'));
167 $originalRootline = [
168 0 => [
'uid' => 2,
'title' =>
'originalTitle'],
169 1 => [
'uid' => 3,
'title' =>
'originalTitle2'],
172 $newInvalidRootline = [
173 0 => [
'uid' => 1,
'title' =>
'newTitle'],
174 1 => [
'uid' => 2,
'title' =>
'newTitle2'],
177 $this->expectException(\RuntimeException::class);
178 $this->expectExceptionCode(1370419654);
180 $this->templateServiceMock->_set(
'rootLine', $originalRootline);
181 $this->templateServiceMock->updateRootlineData($newInvalidRootline);