|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace KamiYang\ProjectVersion\Tests\Unit\Backend\ToolbarItems; |
|
5
|
|
|
|
|
6
|
|
|
/* |
|
7
|
|
|
* This file is part of the ProjectVersion project. |
|
8
|
|
|
* |
|
9
|
|
|
* It is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU General Public License as published by |
|
11
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
12
|
|
|
* (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, please read |
|
15
|
|
|
* LICENSE file that was distributed with this source code. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
use KamiYang\ProjectVersion\Backend\ToolbarItems\ProjectVersionSlot; |
|
19
|
|
|
use KamiYang\ProjectVersion\Facade\LocalizationUtilityFacade; |
|
20
|
|
|
use KamiYang\ProjectVersion\Service\ProjectVersion; |
|
21
|
|
|
use KamiYang\ProjectVersion\Service\ProjectVersionService; |
|
22
|
|
|
use Nimut\TestingFramework\TestCase\UnitTestCase; |
|
23
|
|
|
use TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem; |
|
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
25
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class ProjectVersionSlotTest |
|
29
|
|
|
*/ |
|
30
|
|
|
class ProjectVersionSlotTest extends UnitTestCase |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var \KamiYang\ProjectVersion\Backend\ToolbarItems\ProjectVersionSlot |
|
34
|
|
|
*/ |
|
35
|
|
|
private $subject; |
|
36
|
|
|
|
|
37
|
|
|
protected function setUp() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->subject = new ProjectVersionSlot(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function tearDown() |
|
43
|
|
|
{ |
|
44
|
|
|
GeneralUtility::purgeInstances(); |
|
45
|
|
|
|
|
46
|
|
|
parent::tearDown(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @test |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getProjectVersionShouldAddProjectVersionAsSystemInformation() |
|
53
|
|
|
{ |
|
54
|
|
|
$version = '9000-rc.69'; |
|
55
|
|
|
$title = 'Project Version'; |
|
56
|
|
|
$iconIdentifier = 'information-project-version'; |
|
57
|
|
|
|
|
58
|
|
|
$projectVersion = new ProjectVersion(); |
|
59
|
|
|
$projectVersion->setVersion($version); |
|
60
|
|
|
$projectVersion->setTitle($title); |
|
61
|
|
|
|
|
62
|
|
|
$systemInformationToolbarItemProphecy = $this->prophesize(SystemInformationToolbarItem::class); |
|
63
|
|
|
|
|
64
|
|
|
$projectVersionServiceProphecy = $this->prophesize(ProjectVersionService::class); |
|
65
|
|
|
$projectVersionServiceProphecy->getProjectVersion()->willReturn($projectVersion); |
|
66
|
|
|
|
|
67
|
|
|
$objectManagerProphecy = $this->prophesize(ObjectManager::class); |
|
68
|
|
|
$objectManagerProphecy->get(ProjectVersionService::class)->willReturn($projectVersionServiceProphecy->reveal()); |
|
69
|
|
|
|
|
70
|
|
|
GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); |
|
71
|
|
|
GeneralUtility::setSingletonInstance(ProjectVersionService::class, $projectVersionServiceProphecy->reveal()); |
|
72
|
|
|
|
|
73
|
|
|
$this->subject->getProjectVersion($systemInformationToolbarItemProphecy->reveal()); |
|
74
|
|
|
|
|
75
|
|
|
$systemInformationToolbarItemProphecy->addSystemInformation($title, $version, $iconIdentifier) |
|
76
|
|
|
->shouldHaveBeenCalledTimes(1); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @test |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getProjectVersionShouldResolveCurrentVersionAndLocalizeItIfNecessary() |
|
83
|
|
|
{ |
|
84
|
|
|
$initialVersionValue = 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf:toolbarItems.sysinfo.project-version.unknown'; |
|
85
|
|
|
$projectVersion = new ProjectVersion(); |
|
86
|
|
|
$projectVersion->setVersion($initialVersionValue); |
|
87
|
|
|
$expectedVersion = 'Unknown project version'; |
|
88
|
|
|
|
|
89
|
|
|
$projectVersionServiceProphecy = $this->prophesize(ProjectVersionService::class); |
|
90
|
|
|
$projectVersionServiceProphecy->getProjectVersion()->willReturn($projectVersion); |
|
91
|
|
|
|
|
92
|
|
|
$objectManagerProphecy = $this->prophesize(ObjectManager::class); |
|
93
|
|
|
$objectManagerProphecy->get(ProjectVersionService::class)->willReturn($projectVersionServiceProphecy->reveal()); |
|
94
|
|
|
|
|
95
|
|
|
$localizationUtilityFacadeProphecy = $this->prophesize(LocalizationUtilityFacade::class); |
|
96
|
|
|
$localizationUtilityFacadeProphecy->translate($initialVersionValue)->willReturn($expectedVersion); |
|
97
|
|
|
|
|
98
|
|
|
GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); |
|
99
|
|
|
GeneralUtility::setSingletonInstance(ProjectVersionService::class, $projectVersionServiceProphecy->reveal()); |
|
100
|
|
|
GeneralUtility::addInstance(LocalizationUtilityFacade::class, $localizationUtilityFacadeProphecy->reveal()); |
|
101
|
|
|
|
|
102
|
|
|
$systemInformationToolbarItemProphecy = $this->prophesize(SystemInformationToolbarItem::class); |
|
103
|
|
|
$actual = $this->subject->getProjectVersion($systemInformationToolbarItemProphecy->reveal()); |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$systemInformationToolbarItemProphecy->addSystemInformation( |
|
106
|
|
|
$projectVersion->getTitle(), |
|
107
|
|
|
$expectedVersion, |
|
108
|
|
|
$projectVersion->getIconIdentifier() |
|
109
|
|
|
) |
|
110
|
|
|
->shouldHaveBeenCalledTimes(1); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.