avatar.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. use OC\Avatar;
  9. class Test_Avatar extends \Test\TestCase {
  10. private static $trashBinStatus;
  11. /** @var @var string */
  12. private $user;
  13. protected function setUp() {
  14. parent::setUp();
  15. $this->user = $this->getUniqueID();
  16. $storage = new \OC\Files\Storage\Temporary(array());
  17. \OC\Files\Filesystem::mount($storage, array(), '/' . $this->user . '/');
  18. }
  19. public static function setUpBeforeClass() {
  20. self::$trashBinStatus = \OC_App::isEnabled('files_trashbin');
  21. \OC_App::disable('files_trashbin');
  22. }
  23. public static function tearDownAfterClass() {
  24. if (self::$trashBinStatus) {
  25. \OC_App::enable('files_trashbin');
  26. }
  27. }
  28. public function testAvatar() {
  29. $avatar = new Avatar($this->user);
  30. $this->assertEquals(false, $avatar->get());
  31. $expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
  32. $expected->resize(64);
  33. $avatar->set($expected->data());
  34. $this->assertEquals($expected->data(), $avatar->get()->data());
  35. $avatar->remove();
  36. $this->assertEquals(false, $avatar->get());
  37. }
  38. public function testAvatarApi() {
  39. $avatarManager = \OC::$server->getAvatarManager();
  40. $avatar = $avatarManager->getAvatar($this->user);
  41. $this->assertEquals(false, $avatar->get());
  42. $expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
  43. $expected->resize(64);
  44. $avatar->set($expected->data());
  45. $this->assertEquals($expected->data(), $avatar->get()->data());
  46. $avatar->remove();
  47. $this->assertEquals(false, $avatar->get());
  48. }
  49. }