summaryrefslogtreecommitdiff
path: root/tests/units/User/Avatar/LetterAvatarProviderTest.php
blob: c145967bf660ede5f24a5ee74559265c699b32b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

require_once __DIR__.'/../../Base.php';

use Kanboard\User\Avatar\LetterAvatarProvider;

class LetterAvatarProviderTest extends Base
{
    public function testGetBackgroundColor()
    {
        $provider = new LetterAvatarProvider($this->container);
        $rgb = $provider->getBackgroundColor('Test');
        $this->assertEquals(array(107, 83, 172), $rgb);
    }

    public function testIsActive()
    {
        $provider = new LetterAvatarProvider($this->container);
        $this->assertTrue($provider->isActive(array()));
    }

    public function testRenderWithFullName()
    {
        $provider = new LetterAvatarProvider($this->container);
        $user = array('id' => 123, 'name' => 'Kanboard Admin', 'username' => 'bob', 'email' => '');
        $expected = '<div class="avatar-letter" style="background-color: rgb(120, 83, 58)" title="Kanboard Admin">KA</div>';
        $this->assertEquals($expected, $provider->render($user, 48));
    }

    public function testRenderWithUsername()
    {
        $provider = new LetterAvatarProvider($this->container);
        $user = array('id' => 123, 'name' => '', 'username' => 'admin', 'email' => '');
        $expected = '<div class="avatar-letter" style="background-color: rgb(134, 45, 132)" title="admin">A</div>';
        $this->assertEquals($expected, $provider->render($user, 48));
    }

    public function testRenderWithUTF8()
    {
        $provider = new LetterAvatarProvider($this->container);
        $user = array('id' => 123, 'name' => 'ü', 'username' => 'admin', 'email' => '');
        $expected = '<div class="avatar-letter" style="background-color: rgb(62, 147, 31)" title="ü">Ü</div>';
        $this->assertEquals($expected, $provider->render($user, 48));
    }
}