[TASK] Remove dependency to extbase from reports module
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Tests / Unit / Report / ServicesListReportTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\Reports\Tests\Unit\Report;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
20 use TYPO3\CMS\Core\Localization\LanguageService;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Extbase\Mvc\Request;
23 use TYPO3\CMS\Fluid\View\StandaloneView;
24 use TYPO3\CMS\Reports\Controller\ReportController;
25 use TYPO3\CMS\Reports\Report\ServicesListReport;
26
27 /**
28 * Test case for class ServicesListReport
29 */
30 class ServicesListReportTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
31 {
32 /**
33 * @var ServicesListReport
34 */
35 protected $subject;
36
37 /**
38 * SetUp
39 */
40 public function setUp()
41 {
42 $GLOBALS['LANG'] = $this->languageServiceProphecy()->reveal();
43 $this->subject = new ServicesListReport(
44 $this->reportControllerProphecy()->reveal()
45 );
46 }
47
48 /**
49 * @test
50 */
51 public function getReportCollectsRelevantDataToAssignThemToTemplateForResponse()
52 {
53 $standaloneViewProphecy = $this->standaloneViewProphecy();
54
55 $this->subject->getReport();
56
57 $standaloneViewProphecy
58 ->assignMultiple(Argument::withEntry('servicesList', []))
59 ->shouldHaveBeenCalled();
60 $standaloneViewProphecy
61 ->assignMultiple(Argument::withKey('searchPaths'))
62 ->shouldHaveBeenCalled();
63 }
64
65 /**
66 * @return ObjectProphecy
67 * @internal param $templatePath
68 */
69 private function standaloneViewProphecy(): ObjectProphecy
70 {
71 $templatePath = GeneralUtility::getFileAbsFileName(
72 'EXT:reports/Resources/Private/Templates/ServicesListReport.html'
73 );
74 $serverRequestProphecy = $this->prophesize(Request::class);
75 /** @var ObjectProphecy $standaloneViewProphecy */
76 $standaloneViewProphecy = $this->prophesize(StandaloneView::class);
77 $standaloneViewProphecy->getRequest()->willReturn($serverRequestProphecy->reveal());
78 $standaloneViewProphecy->setTemplatePathAndFilename($templatePath)->shouldBeCalled();
79 $standaloneViewProphecy->assignMultiple(Argument::any())->willReturn($standaloneViewProphecy->reveal());
80 $standaloneViewProphecy->render()->willReturn('<p>Template output</p>');
81 GeneralUtility::addInstance(StandaloneView::class, $standaloneViewProphecy->reveal());
82
83 return $standaloneViewProphecy;
84 }
85
86 /**
87 * @return ObjectProphecy
88 */
89 private function languageServiceProphecy(): ObjectProphecy
90 {
91 $languageServiceProphecy = $this->prophesize(LanguageService::class);
92 $languageServiceProphecy
93 ->includeLLFile('EXT:reports/Resources/Private/Language/locallang_servicereport.xlf')
94 ->willReturn(null)
95 ->shouldBeCalled();
96 $languageServiceProphecy->getLL(Argument::any())->willReturn('translation string');
97 return $languageServiceProphecy;
98 }
99
100 /**
101 * @return ObjectProphecy
102 */
103 private function reportControllerProphecy(): ObjectProphecy
104 {
105 $reportControllerProphecy = $this->prophesize(ReportController::class);
106 return $reportControllerProphecy;
107 }
108 }