aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-06-15 16:16:13 +0200
committerGitHub <noreply@github.com>2018-06-15 16:16:13 +0200
commitd82ef721611654aa3a3aab0ea3c8c85c7e0187d6 (patch)
tree2b75f2c5bad51beeec55f1da359a01abf1608048 /tests
parenta0496b2a7802d7605063056999ab0f3d465957af (diff)
parent543188d0cb2f03e661ba937dcef5f56f739ea582 (diff)
downloadnextcloud-server-d82ef721611654aa3a3aab0ea3c8c85c7e0187d6.tar.gz
nextcloud-server-d82ef721611654aa3a3aab0ea3c8c85c7e0187d6.zip
Merge pull request #9197 from nextcloud/fix-avatar-center
Fix avatar generator centering
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/AvatarTest.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lib/AvatarTest.php b/tests/lib/AvatarTest.php
index 4914c02bd14..759dd385564 100644
--- a/tests/lib/AvatarTest.php
+++ b/tests/lib/AvatarTest.php
@@ -48,6 +48,9 @@ class AvatarTest extends \Test\TestCase {
$this->createMock(ILogger::class),
$this->config
);
+
+ // abcdefghi is a convenient name that our algorithm convert to our nextcloud blue 0082c9
+ $this->user->method('getDisplayName')->willReturn('abcdefghi');
}
public function testGetNoAvatar() {
@@ -226,4 +229,37 @@ class AvatarTest extends \Test\TestCase {
$this->avatar->set($image->data());
}
+ public function testGenerateSvgAvatar() {
+ $avatar = $this->invokePrivate($this->avatar, 'getAvatarVector', [64]);
+
+ $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+ <svg width="64" height="64" version="1.1" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
+ <rect width="100%" height="100%" fill="#0082c9"></rect>
+ <text x="50%" y="350" style="font-weight:600;font-size:278px;font-family:\'Open Sans\';text-anchor:middle;fill:#fff">A</text>
+ </svg>';
+ $this->assertEquals($avatar, $svg);
+ }
+
+ public function testHashToInt() {
+ $hashToInt = $this->invokePrivate($this->avatar, 'hashToInt', ['abcdef', 18]);
+ $this->assertTrue(gettype($hashToInt) === 'integer');
+ }
+
+ public function testMixPalette() {
+ $colorFrom = new \OC\Color(0,0,0);
+ $colorTo = new \OC\Color(6,12,18);
+ $steps = 6;
+ $palette = $this->invokePrivate($this->avatar, 'mixPalette', [$steps, $colorFrom, $colorTo]);
+ foreach($palette as $j => $color) {
+ // calc increment
+ $incR = $colorTo->r / $steps * $j;
+ $incG = $colorTo->g / $steps * $j;
+ $incB = $colorTo->b / $steps * $j;
+ // ensure everything is equal
+ $this->assertEquals($color, new \OC\Color($incR, $incG,$incB));
+ }
+ $hashToInt = $this->invokePrivate($this->avatar, 'hashToInt', ['abcdef', 18]);
+ $this->assertTrue(gettype($hashToInt) === 'integer');
+ }
+
}