GuestAvatarTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. public function testGet() {
  56. $this->markTestSkipped('TODO: Disable because fails on drone');
  57. $avatar = $this->guestAvatar->getFile(32);
  58. self::assertInstanceOf(InMemoryFile::class, $avatar);
  59. $expectedFile = file_get_contents(
  60. __DIR__ . '/../../data/guest_avatar_einstein_32.png'
  61. );
  62. self::assertEquals(trim($expectedFile), trim($avatar->getContent()));
  63. }
  64. /**
  65. * Asserts that "testIsCustomAvatar" returns false for guests.
  66. *
  67. * @return void
  68. */
  69. public function testIsCustomAvatar() {
  70. self::assertFalse($this->guestAvatar->isCustomAvatar());
  71. }
  72. }