[!!!][TASK] Move service report from EXT:sv to EXT:reports
[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\Fluid\View\StandaloneView;
23 use TYPO3\CMS\Reports\Controller\ReportController;
24 use TYPO3\CMS\Reports\Report\ServicesListReport;
25
26 /**
27 * Test case for class ServicesListReport
28 */
29 class ServicesListReportTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
30 {
31 /**
32 * @var ServicesListReport
33 */
34 protected $subject;
35
36 /**
37 * SetUp
38 */
39 public function setUp()
40 {
41 $GLOBALS['LANG'] = $this->languageServiceProphecy()->reveal();
42 $this->subject = new ServicesListReport(
43 $this->reportControllerProphecy()->reveal()
44 );
45 }
46
47 /**
48 * @test
49 */
50 public function getReportCollectsRelevantDataToAssignThemToTemplateForResponse()
51 {
52 $standaloneViewProphecy = $this->standaloneViewProphecy();
53
54 $this->subject->getReport();
55
56 $standaloneViewProphecy
57 ->assignMultiple(Argument::withEntry('servicesList', []))
58 ->shouldHaveBeenCalled();
59 $standaloneViewProphecy
60 ->assignMultiple(Argument::withKey('searchPaths'))
61 ->shouldHaveBeenCalled();
62 }
63
64 /**
65 * @return ObjectProphecy
66 * @internal param $templatePath
67 */
68 private function standaloneViewProphecy(): ObjectProphecy
69 {
70 $templatePath = GeneralUtility::getFileAbsFileName(
71 'EXT:reports/Resources/Private/Templates/ServicesListReport.html'
72 );
73 $standaloneViewProphecy = $this->prophesize(StandaloneView::class);
74 $standaloneViewProphecy->setTemplatePathAndFilename($templatePath)->shouldBeCalled();
75 $standaloneViewProphecy->assignMultiple(Argument::any())->willReturn($standaloneViewProphecy->reveal());
76 $standaloneViewProphecy->render()->willReturn('<p>Template output</p>');
77 GeneralUtility::addInstance(StandaloneView::class, $standaloneViewProphecy->reveal());
78
79 return $standaloneViewProphecy;
80 }
81
82 /**
83 * @return ObjectProphecy
84 */
85 private function languageServiceProphecy(): ObjectProphecy
86 {
87 $languageServiceProphecy = $this->prophesize(LanguageService::class);
88 $languageServiceProphecy
89 ->includeLLFile('EXT:reports/Resources/Private/Language/locallang_servicereport.xlf')
90 ->willReturn(null)
91 ->shouldBeCalled();
92 $languageServiceProphecy->getLL(Argument::any())->willReturn('translation string');
93 return $languageServiceProphecy;
94 }
95
96 /**
97 * @return ObjectProphecy
98 */
99 private function reportControllerProphecy(): ObjectProphecy
100 {
101 $reportControllerProphecy = $this->prophesize(ReportController::class);
102 return $reportControllerProphecy;
103 }
104 }