GuestAvatarTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018, Michael Weimann <mail@michael-weimann.eu>
  5. *
  6. * @author Michael Weimann <mail@michael-weimann.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. */
  22. namespace Test\Avatar;
  23. use OC\Avatar\GuestAvatar;
  24. use OCP\Files\SimpleFS\InMemoryFile;
  25. use PHPUnit\Framework\MockObject\MockObject;
  26. use Psr\Log\LoggerInterface;
  27. use Test\TestCase;
  28. /**
  29. * This class provides test cases for the GuestAvatar class.
  30. *
  31. * @package Test\Avatar
  32. */
  33. class GuestAvatarTest extends TestCase {
  34. /**
  35. * @var GuestAvatar
  36. */
  37. private $guestAvatar;
  38. /**
  39. * Setups a guest avatar instance for tests.
  40. *
  41. * @before
  42. * @return void
  43. */
  44. public function setupGuestAvatar() {
  45. /* @var MockObject|LoggerInterface $logger */
  46. $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
  47. $this->guestAvatar = new GuestAvatar('einstein', $logger);
  48. }
  49. /**
  50. * Asserts that testGet() returns the expected avatar.
  51. *
  52. * For the test a static name "einstein" is used and
  53. * the generated image is compared with an expected one.
  54. *
  55. * @return void
  56. */
  57. public function testGet() {
  58. $avatar = $this->guestAvatar->getFile(32);
  59. self::assertInstanceOf(InMemoryFile::class, $avatar);
  60. $expectedFile = file_get_contents(
  61. __DIR__ . '/../../data/guest_avatar_einstein_32.png'
  62. );
  63. self::assertEquals(trim($expectedFile), trim($avatar->getContent()));
  64. }
  65. /**
  66. * Asserts that "testIsCustomAvatar" returns false for guests.
  67. *
  68. * @return void
  69. */
  70. public function testIsCustomAvatar() {
  71. self::assertFalse($this->guestAvatar->isCustomAvatar());
  72. }
  73. }