2525namespace OCA \UpdateNotification \Tests \Controller ;
2626
2727use OCA \UpdateNotification \Controller \AdminController ;
28+ use OCA \UpdateNotification \ResetTokenBackgroundJob ;
2829use OCA \UpdateNotification \UpdateChecker ;
2930use OCP \AppFramework \Http \DataResponse ;
3031use OCP \AppFramework \Http \TemplateResponse ;
3536use OCP \IL10N ;
3637use OCP \IRequest ;
3738use OCP \Security \ISecureRandom ;
39+ use OCP \Util ;
3840use Test \TestCase ;
3941
4042class AdminControllerTest extends TestCase {
41- /** @var IRequest */
43+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
4244 private $ request ;
43- /** @var IJobList */
45+ /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
4446 private $ jobList ;
45- /** @var ISecureRandom */
47+ /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
4648 private $ secureRandom ;
47- /** @var IConfig */
49+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
4850 private $ config ;
4951 /** @var AdminController */
5052 private $ adminController ;
51- /** @var ITimeFactory */
53+ /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
5254 private $ timeFactory ;
53- /** @var IL10N */
55+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
5456 private $ l10n ;
55- /** @var UpdateChecker */
57+ /** @var UpdateChecker|\PHPUnit_Framework_MockObject_MockObject */
5658 private $ updateChecker ;
57- /** @var IDateTimeFormatter */
59+ /** @var IDateTimeFormatter|\PHPUnit_Framework_MockObject_MockObject */
5860 private $ dateTimeFormatter ;
5961
6062 public function setUp () {
6163 parent ::setUp ();
6264
63- $ this ->request = $ this ->getMockBuilder ('\\OCP \\IRequest ' )->getMock ();
64- $ this ->jobList = $ this ->getMockBuilder ('\\OCP \\BackgroundJob \\IJobList ' )->getMock ();
65- $ this ->secureRandom = $ this ->getMockBuilder ('\\OCP \\Security \\ISecureRandom ' )->getMock ();
66- $ this ->config = $ this ->getMockBuilder ('\\OCP \\IConfig ' )->getMock ();
67- $ this ->timeFactory = $ this ->getMockBuilder ('\\OCP \\AppFramework \\Utility \\ITimeFactory ' )->getMock ();
68- $ this ->l10n = $ this ->getMockBuilder ('\\OCP \\IL10N ' )->getMock ();
69- $ this ->updateChecker = $ this ->getMockBuilder ('\\OCA \\UpdateNotification \\UpdateChecker ' )
70- ->disableOriginalConstructor ()->getMock ();
71- $ this ->dateTimeFormatter = $ this ->getMockBuilder ('\\OCP \\IDateTimeFormatter ' )->getMock ();
65+ $ this ->request = $ this ->createMock (IRequest::class);
66+ $ this ->jobList = $ this ->createMock (IJobList::class);
67+ $ this ->secureRandom = $ this ->createMock (ISecureRandom::class);
68+ $ this ->config = $ this ->createMock (IConfig::class);
69+ $ this ->timeFactory = $ this ->createMock (ITimeFactory::class);
70+ $ this ->l10n = $ this ->createMock (IL10N ::class);
71+ $ this ->updateChecker = $ this ->createMock (UpdateChecker::class);
72+ $ this ->dateTimeFormatter = $ this ->createMock (IDateTimeFormatter::class);
7273
7374 $ this ->adminController = new AdminController (
7475 'updatenotification ' ,
@@ -83,17 +84,17 @@ public function setUp() {
8384 );
8485 }
8586
86- public function testDisplayPanelWithUpdate () {
87+ public function testGetFormWithUpdate () {
8788 $ channels = [
8889 'daily ' ,
8990 'beta ' ,
9091 'stable ' ,
9192 'production ' ,
9293 ];
93- $ currentChannel = \ OCP \ Util::getChannel ();
94+ $ currentChannel = Util::getChannel ();
9495
9596 // Remove the currently used channel from the channels list
96- if (($ key = array_search ($ currentChannel , $ channels )) !== false ) {
97+ if (($ key = array_search ($ currentChannel , $ channels, true )) !== false ) {
9798 unset($ channels [$ key ]);
9899 }
99100
@@ -128,7 +129,7 @@ public function testDisplayPanelWithUpdate() {
128129 'isNewVersionAvailable ' => true ,
129130 'isUpdateChecked ' => true ,
130131 'lastChecked ' => 'LastCheckedReturnValue ' ,
131- 'currentChannel ' => \ OCP \ Util::getChannel (),
132+ 'currentChannel ' => Util::getChannel (),
132133 'channels ' => $ channels ,
133134 'newVersionString ' => '8.1.2 ' ,
134135 'downloadLink ' => 'https://downloads.nextcloud.org/server ' ,
@@ -139,20 +140,20 @@ public function testDisplayPanelWithUpdate() {
139140 ];
140141
141142 $ expected = new TemplateResponse ('updatenotification ' , 'admin ' , $ params , '' );
142- $ this ->assertEquals ($ expected , $ this ->adminController ->displayPanel ());
143+ $ this ->assertEquals ($ expected , $ this ->adminController ->getForm ());
143144 }
144145
145- public function testDisplayPanelWithoutUpdate () {
146+ public function testGetFormWithoutUpdate () {
146147 $ channels = [
147148 'daily ' ,
148149 'beta ' ,
149150 'stable ' ,
150151 'production ' ,
151152 ];
152- $ currentChannel = \ OCP \ Util::getChannel ();
153+ $ currentChannel = Util::getChannel ();
153154
154155 // Remove the currently used channel from the channels list
155- if (($ key = array_search ($ currentChannel , $ channels )) !== false ) {
156+ if (($ key = array_search ($ currentChannel , $ channels, true )) !== false ) {
156157 unset($ channels [$ key ]);
157158 }
158159
@@ -182,7 +183,7 @@ public function testDisplayPanelWithoutUpdate() {
182183 'isNewVersionAvailable ' => false ,
183184 'isUpdateChecked ' => true ,
184185 'lastChecked ' => 'LastCheckedReturnValue ' ,
185- 'currentChannel ' => \ OCP \ Util::getChannel (),
186+ 'currentChannel ' => Util::getChannel (),
186187 'channels ' => $ channels ,
187188 'newVersionString ' => '' ,
188189 'downloadLink ' => '' ,
@@ -193,15 +194,15 @@ public function testDisplayPanelWithoutUpdate() {
193194 ];
194195
195196 $ expected = new TemplateResponse ('updatenotification ' , 'admin ' , $ params , '' );
196- $ this ->assertEquals ($ expected , $ this ->adminController ->displayPanel ());
197+ $ this ->assertEquals ($ expected , $ this ->adminController ->getForm ());
197198 }
198199
199200
200201 public function testCreateCredentials () {
201202 $ this ->jobList
202203 ->expects ($ this ->once ())
203204 ->method ('add ' )
204- ->with (' OCA\UpdateNotification\ ResetTokenBackgroundJob' );
205+ ->with (ResetTokenBackgroundJob::class );
205206 $ this ->secureRandom
206207 ->expects ($ this ->once ())
207208 ->method ('generate ' )
0 commit comments