summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorkondou <kondou@ts.unde.re>2013-07-30 16:09:54 +0200
committerkondou <kondou@ts.unde.re>2013-08-25 21:04:09 +0200
commit2bfe66223563b16a067be273e0d6979b420598ad (patch)
treedbe49438dc9c2175895eedb442e9e1630bc01b67 /tests
parentfac671b14ed06233d37ad38194ebf9a99118644a (diff)
downloadnextcloud-server-2bfe66223563b16a067be273e0d6979b420598ad.tar.gz
nextcloud-server-2bfe66223563b16a067be273e0d6979b420598ad.zip
Add unittests & check filetype in setLocalAvatar()
TODO: Fix OC_Image->mimetype(), it always returns "image/png"
Diffstat (limited to 'tests')
-rw-r--r--tests/data/testavatar.pngbin0 -> 3705 bytes
-rw-r--r--tests/lib/avatar.php61
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/data/testavatar.png b/tests/data/testavatar.png
new file mode 100644
index 00000000000..24770fb634f
--- /dev/null
+++ b/tests/data/testavatar.png
Binary files differ
diff --git a/tests/lib/avatar.php b/tests/lib/avatar.php
new file mode 100644
index 00000000000..b1d9f46ed09
--- /dev/null
+++ b/tests/lib/avatar.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_Avatar extends PHPUnit_Framework_TestCase {
+
+ public function testModes() {
+ $this->assertEquals('local', \OC_Avatar::getMode());
+
+ \OC_Config::setValue('avatar', 'local');
+ $this->assertEquals('local', \OC_Avatar::getMode());
+
+ \OC_Config::setValue('avatar', 'gravatar');
+ $this->assertEquals('gravatar', \OC_Avatar::getMode());
+
+ \OC_Config::setValue('avatar', 'none');
+ $this->assertEquals('none', \OC_Avatar::getMode());
+ }
+
+ public function testDisabledAvatar() {
+ \OC_Config::setValue('avatar', 'none');
+ $this->assertFalse(\OC_Avatar::get(\OC_User::getUser()));
+ $this->assertFalse(\OC_Avatar::get(\OC_User::getUser(), 32));
+ }
+
+ public function testLocalAvatar() {
+ \OC_Config::setValue('avatar', 'local');
+ $this->assertEquals(\OC_Avatar::get(\OC_User::getUser()), \OC_Avatar::wrapIntoImg(\OC_Avatar::getDefaultAvatar(), 'png'));
+
+ $expected = new OC_Image(\OC::$SERVERROOT.'/tests/data/testavatar.png');
+ \OC_Avatar::setLocalAvatar(\OC_User::getUser(), $expected->data());
+ $expected->resize(32);
+ $this->assertEquals($expected, \OC_Avatar::get(\OC_User::getUser()));
+
+ \OC_Avatar::setLocalAvatar(\OC_User::getUser(), false);
+ $this->assertEquals(\OC_Avatar::get(\OC_User::getUser()), \OC_Avatar::wrapIntoImg(\OC_Avatar::getDefaultAvatar(), 'png'));
+ }
+
+ public function testGravatar() {
+ \OC_Preferences::setValue(\OC_User::getUser(), 'settings', 'email', 'someone@example.com');
+ \OC_Config::setValue('avatar', 'gravatar');
+ $expected = "http://www.gravatar.com/avatar/".md5("someone@example.com")."?s=";
+ $this->assertEquals($expected."64", \OC_Avatar::get(\OC_User::getUser()));
+ $this->assertEquals($expected."32", \OC_Avatar::get(\OC_User::getUser(), 32));
+ }
+
+ public function testDefaultAvatar() {
+ $img = new \OC_Image(OC::$SERVERROOT.'/core/img/defaultavatar.png');
+ $img->resize(128);
+ $this->assertEquals((string)$img, \OC_Avatar::getDefaultAvatar(128));
+ }
+
+ public function testWrapIntoImg() {
+ $expected = "data:image/test;base64,DUMMY==123==";
+ $this->assertEquals($expected, \OC_Avatar::wrapIntoImg("DUMMY==123==", "test"));
+ }
+}