|
49 | 49 | use OCP\Files\IAppData; |
50 | 50 | use OCP\Files\NotFoundException; |
51 | 51 | use OCP\Files\SimpleFS\ISimpleFile; |
52 | | -use OCP\Files\SimpleFS\ISimpleFolder; |
53 | 52 | use OCP\IConfig; |
54 | 53 | use OCP\IL10N; |
55 | 54 | use OCP\IRequest; |
56 | 55 | use OCP\ITempManager; |
57 | 56 | use OCP\IURLGenerator; |
| 57 | +use PHPUnit\Framework\MockObject\MockObject; |
58 | 58 | use Test\TestCase; |
59 | 59 |
|
60 | 60 | class ThemingControllerTest extends TestCase { |
@@ -98,12 +98,12 @@ protected function setUp(): void { |
98 | 98 | $this->urlGenerator = $this->createMock(IURLGenerator::class); |
99 | 99 | $this->imageManager = $this->createMock(ImageManager::class); |
100 | 100 |
|
101 | | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
102 | | - $this->timeFactory->expects($this->any()) |
| 101 | + $timeFactory = $this->createMock(ITimeFactory::class); |
| 102 | + $timeFactory->expects($this->any()) |
103 | 103 | ->method('getTime') |
104 | 104 | ->willReturn(123); |
105 | 105 |
|
106 | | - $this->overwriteService(ITimeFactory::class, $this->timeFactory); |
| 106 | + $this->overwriteService(ITimeFactory::class, $timeFactory); |
107 | 107 |
|
108 | 108 | $this->themingController = new ThemingController( |
109 | 109 | 'theming', |
@@ -293,12 +293,9 @@ public function testUploadSVGFaviconWithoutImagemagick() { |
293 | 293 | return $str; |
294 | 294 | }); |
295 | 295 |
|
296 | | - $folder = $this->createMock(ISimpleFolder::class); |
297 | | - $this->appData |
298 | | - ->expects($this->once()) |
299 | | - ->method('getFolder') |
300 | | - ->with('images') |
301 | | - ->willReturn($folder); |
| 296 | + $this->imageManager->expects($this->once()) |
| 297 | + ->method('updateImage') |
| 298 | + ->willThrowException(new \Exception('Unsupported image type')); |
302 | 299 |
|
303 | 300 | $expected = new DataResponse( |
304 | 301 | [ |
@@ -337,12 +334,9 @@ public function testUpdateLogoInvalidMimeType() { |
337 | 334 | return $str; |
338 | 335 | }); |
339 | 336 |
|
340 | | - $folder = $this->createMock(ISimpleFolder::class); |
341 | | - $this->appData |
342 | | - ->expects($this->once()) |
343 | | - ->method('getFolder') |
344 | | - ->with('images') |
345 | | - ->willReturn($folder); |
| 337 | + $this->imageManager->expects($this->once()) |
| 338 | + ->method('updateImage') |
| 339 | + ->willThrowException(new \Exception('Unsupported image type')); |
346 | 340 |
|
347 | 341 | $expected = new DataResponse( |
348 | 342 | [ |
@@ -398,38 +392,17 @@ public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists=true) { |
398 | 392 | return $str; |
399 | 393 | }); |
400 | 394 |
|
401 | | - |
402 | | - $file = $this->createMock(ISimpleFile::class); |
403 | | - $folder = $this->createMock(ISimpleFolder::class); |
404 | | - if ($folderExists) { |
405 | | - $this->appData |
406 | | - ->expects($this->once()) |
407 | | - ->method('getFolder') |
408 | | - ->with('images') |
409 | | - ->willReturn($folder); |
410 | | - } else { |
411 | | - $this->appData |
412 | | - ->expects($this->at(0)) |
413 | | - ->method('getFolder') |
414 | | - ->with('images') |
415 | | - ->willThrowException(new NotFoundException()); |
416 | | - $this->appData |
417 | | - ->expects($this->at(1)) |
418 | | - ->method('newFolder') |
419 | | - ->with('images') |
420 | | - ->willReturn($folder); |
421 | | - } |
422 | | - $folder->expects($this->once()) |
423 | | - ->method('newFile') |
424 | | - ->with('logo') |
425 | | - ->willReturn($file); |
426 | 395 | $this->urlGenerator->expects($this->once()) |
427 | 396 | ->method('linkTo') |
428 | 397 | ->willReturn('serverCss'); |
429 | 398 | $this->imageManager->expects($this->once()) |
430 | 399 | ->method('getImageUrl') |
431 | 400 | ->with('logo') |
432 | 401 | ->willReturn('imageUrl'); |
| 402 | + |
| 403 | + $this->imageManager->expects($this->once()) |
| 404 | + ->method('updateImage'); |
| 405 | + |
433 | 406 | $expected = new DataResponse( |
434 | 407 | [ |
435 | 408 | 'data' => |
@@ -474,30 +447,8 @@ public function testUpdateLogoLoginScreenUpload($folderExists) { |
474 | 447 | return $str; |
475 | 448 | }); |
476 | 449 |
|
477 | | - $file = $this->createMock(ISimpleFile::class); |
478 | | - $folder = $this->createMock(ISimpleFolder::class); |
479 | | - if ($folderExists) { |
480 | | - $this->appData |
481 | | - ->expects($this->once()) |
482 | | - ->method('getFolder') |
483 | | - ->with('images') |
484 | | - ->willReturn($folder); |
485 | | - } else { |
486 | | - $this->appData |
487 | | - ->expects($this->at(0)) |
488 | | - ->method('getFolder') |
489 | | - ->with('images') |
490 | | - ->willThrowException(new NotFoundException()); |
491 | | - $this->appData |
492 | | - ->expects($this->at(1)) |
493 | | - ->method('newFolder') |
494 | | - ->with('images') |
495 | | - ->willReturn($folder); |
496 | | - } |
497 | | - $folder->expects($this->once()) |
498 | | - ->method('newFile') |
499 | | - ->with('background') |
500 | | - ->willReturn($file); |
| 450 | + $this->imageManager->expects($this->once()) |
| 451 | + ->method('updateImage'); |
501 | 452 |
|
502 | 453 | $this->urlGenerator->expects($this->once()) |
503 | 454 | ->method('linkTo') |
@@ -548,12 +499,9 @@ public function testUpdateLogoLoginScreenUploadWithInvalidImage() { |
548 | 499 | return $str; |
549 | 500 | }); |
550 | 501 |
|
551 | | - $folder = $this->createMock(ISimpleFolder::class); |
552 | | - $this->appData |
553 | | - ->expects($this->once()) |
554 | | - ->method('getFolder') |
555 | | - ->with('images') |
556 | | - ->willReturn($folder); |
| 502 | + $this->imageManager->expects($this->once()) |
| 503 | + ->method('updateImage') |
| 504 | + ->willThrowException(new \Exception('Unsupported image type')); |
557 | 505 |
|
558 | 506 | $expected = new DataResponse( |
559 | 507 | [ |
@@ -723,9 +671,6 @@ public function testUndoDelete($value, $filename) { |
723 | 671 | ->method('linkTo') |
724 | 672 | ->with('', '/core/css/someHash-css-variables.scss') |
725 | 673 | ->willReturn('/nextcloudWebroot/core/css/someHash-css-variables.scss'); |
726 | | - $this->imageManager->expects($this->once()) |
727 | | - ->method('delete') |
728 | | - ->with($filename); |
729 | 674 |
|
730 | 675 | $expected = new DataResponse( |
731 | 676 | [ |
|
0 commit comments