GuestAvatarTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test\Avatar;
  8. use OC\Avatar\GuestAvatar;
  9. use OCP\Files\SimpleFS\InMemoryFile;
  10. use PHPUnit\Framework\MockObject\MockObject;
  11. use Psr\Log\LoggerInterface;
  12. use Test\TestCase;
  13. /**
  14. * This class provides test cases for the GuestAvatar class.
  15. *
  16. * @package Test\Avatar
  17. */
  18. class GuestAvatarTest extends TestCase {
  19. /**
  20. * @var GuestAvatar
  21. */
  22. private $guestAvatar;
  23. /**
  24. * Setups a guest avatar instance for tests.
  25. *
  26. * @before
  27. * @return void
  28. */
  29. public function setupGuestAvatar() {
  30. /* @var MockObject|LoggerInterface $logger */
  31. $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
  32. $this->guestAvatar = new GuestAvatar('einstein', $logger);
  33. }
  34. /**
  35. * Asserts that testGet() returns the expected avatar.
  36. *
  37. * For the test a static name "einstein" is used and
  38. * the generated image is compared with an expected one.
  39. */
  40. public function testGet(): void {
  41. $this->markTestSkipped('TODO: Disable because fails on drone');
  42. $avatar = $this->guestAvatar->getFile(32);
  43. self::assertInstanceOf(InMemoryFile::class, $avatar);
  44. $expectedFile = file_get_contents(
  45. __DIR__ . '/../../data/guest_avatar_einstein_32.png'
  46. );
  47. self::assertEquals(trim($expectedFile), trim($avatar->getContent()));
  48. }
  49. /**
  50. * Asserts that "testIsCustomAvatar" returns false for guests.
  51. *
  52. * @return void
  53. */
  54. public function testIsCustomAvatar(): void {
  55. self::assertFalse($this->guestAvatar->isCustomAvatar());
  56. }
  57. }