forked from laravolt/avatar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvatarLaravelTest.php
151 lines (122 loc) · 5.39 KB
/
AvatarLaravelTest.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
class AvatarLaravelTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
*/
public function it_can_override_attributes_when_instantiated()
{
$config = [
'ascii' => false,
'shape' => 'circle',
'width' => 100,
'height' => 100,
'chars' => 2,
'fontSize' => 48,
'fonts' => ['arial.ttf'],
'foregrounds' => ['#FFFFFF'],
'backgrounds' => ['#000000'],
'border' => ['size' => 1, 'color' => '#999999', 'radius' => 15],
];
$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');
$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('make')->andReturn('AB');
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');
$avatar = new \Laravolt\Avatar\Avatar($config, $cache, $generator);
$this->assertEquals(2, $avatar->getAttribute('chars'));
$this->assertEquals('circle', $avatar->getAttribute('shape'));
$this->assertEquals(100, $avatar->getAttribute('width'));
$this->assertEquals(100, $avatar->getAttribute('height'));
$this->assertEquals(['#000000'], $avatar->getAttribute('availableBackgrounds'));
$this->assertEquals(['#FFFFFF'], $avatar->getAttribute('availableForegrounds'));
$this->assertEquals(['arial.ttf'], $avatar->getAttribute('fonts'));
$this->assertEquals(48, $avatar->getAttribute('fontSize'));
$this->assertEquals(1, $avatar->getAttribute('borderSize'));
$this->assertEquals('#999999', $avatar->getAttribute('borderColor'));
$this->assertEquals(15, $avatar->getAttribute('borderRadius'));
$this->assertEquals(false, $avatar->getAttribute('ascii'));
}
/**
* @test
*/
public function it_have_no_border_radius_as_default()
{
$config = [
'border' => ['size' => 1, 'color' => '#999999'],
];
$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');
$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('make')->andReturn('AB');
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');
$avatar = new \Laravolt\Avatar\Avatar($config, $cache, $generator);
$this->assertEquals(0, $avatar->getAttribute('borderRadius'));
}
/**
* @test
*/
public function it_can_override_attributes_after_set_name()
{
$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');
$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('setName')->andReturnSelf();
$generator->shouldReceive('setLength');
$generator->shouldReceive('make')->andReturn('A');
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');
$generator->shouldReceive('base_path');
$config = ['backgrounds' => ['#000000', '#111111'], 'foregrounds' => ['#EEEEEE', '#FFFFFF']];
$avatar = new \Laravolt\Avatar\Avatar($config, $cache, $generator);
$avatar->create('A');
$this->assertEquals('#FFFFFF', $avatar->getAttribute('foreground'));
}
/**
* @test
*/
public function it_has_correct_random_background()
{
$config = [
'foregrounds' => ['#000000', '#111111'],
'backgrounds' => ['#111111', '#000000'],
];
$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');
$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');
$avatar = new \Laravolt\Avatar\Avatar($config, $cache, $generator);
$name = 'A';
$generator->shouldReceive('setLength')->andReturn(1);
$generator->shouldReceive('setName')->andReturn($name);
$generator->shouldReceive('setUppercase')->andReturnSelf();
$generator->shouldReceive('make')->andReturn('A');
$avatar->create($name)->buildAvatar();
$this->assertEquals('#000000', $avatar->getAttribute('background'));
$this->assertEquals('#111111', $avatar->getAttribute('foreground'));
}
/**
* @test
*/
public function it_has_different_random_background()
{
$config = [
'backgrounds' => ['#000000', '#111111'],
];
$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');
$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');
$name1 = 'B';
$name2 = 'C';
$generator->shouldReceive('setLength')->andReturn(2);
$generator->shouldReceive('setName')->andReturn($name1);
$generator->shouldReceive('make')->andReturn('AA');
$avatar1 = new \Laravolt\Avatar\Avatar($config, $cache, $generator);
$avatar1->create($name1)->buildAvatar();
$generator->shouldReceive('setName')->andReturn($name2);
$avatar2 = new \Laravolt\Avatar\Avatar($config, $cache, $generator);
$avatar2->create($name2)->buildAvatar();
$this->assertEquals('#000000', $avatar1->getAttribute('background'));
$this->assertEquals('#111111', $avatar2->getAttribute('background'));
}
}