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
152
153
154
155
156
157
158
159
160
161
162
|
<?php
/*
* Copyright (C) 2009 - Marcus Lunzenauer <mlunzena@uos.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
require_once 'lib/phplib/Seminar_Perm.class.php';
abstract class AvatarTest extends \Codeception\Test\Unit
{
protected $avatar_id;
protected $avatar;
abstract protected function getType(): string;
protected function createPath(string $avatar_id, ?string $size, bool $subdir): string
{
$result = $avatar_id;
if ($size) {
$result .= "_{$size}";
}
$result .= '.' . Avatar::EXTENSION;
if ($subdir) {
$result = substr($avatar_id, 0, 2) . '/' . $result;
}
return "/dynamic/{$this->getType()}/{$result}";
}
protected function createFixedPath(?string $size): string
{
$result = 'nobody';
if ($size) {
$result .= "_{$size}";
}
$result .= '.' . Avatar::EXTENSION;
return "/fixed/images/avatars/{$this->getType()}/{$result}";
}
protected function setUp(): void
{
$GLOBALS['DYNAMIC_CONTENT_URL'] = "/dynamic";
$GLOBALS['DYNAMIC_CONTENT_PATH'] = "/dynamic";
$GLOBALS['ASSETS_URL'] = "/fixed/";
$GLOBALS['ASSETS_PATH'] = "/fixed/";
Assets::set_assets_url($GLOBALS['ASSETS_URL']);
Assets::set_assets_path($GLOBALS['ASSETS_PATH']);
}
public function tearDown(): void
{
unset(
$GLOBALS['DYNAMIC_CONTENT_PATH'],
$GLOBALS['DYNAMIC_CONTENT_URL'],
$GLOBALS['ASSETS_URL'],
$GLOBALS['ASSETS_PATH']
);
}
public function test_avatar_url()
{
$this->assertEquals(
$this->createPath($this->avatar_id, Avatar::NORMAL, true) . '?d=0',
$this->avatar->getCustomAvatarUrl(Avatar::NORMAL)
);
}
public function test_avatar_path()
{
$this->assertEquals(
$this->createPath($this->avatar_id, Avatar::NORMAL, true),
$this->avatar->getCustomAvatarPath(Avatar::NORMAL)
);
}
public function test_nobody_url()
{
$this->assertEquals(
$this->createFixedPath(Avatar::NORMAL),
$this->avatar->getNobody()->getURL(Avatar::NORMAL)
);
}
public function test_nobody_path()
{
$this->assertEquals(
$this->createFixedPath(Avatar::NORMAL),
$this->avatar->getNobody()->getFilename(Avatar::NORMAL)
);
}
}
/**
* Testcase for Avatar class.
*
* @package studip
* @subpackage test
*
* @author mlunzena
* @copyright (c) Authors
*/
class AvatarTestCase extends AvatarTest
{
public function setUp(): void
{
parent::setUp();
$stub = $this->createMock('Seminar_Perm');
// Configure the stub.
$stub->expects($this->any())
->method('have_perm')
->will($this->returnValue(true));
$GLOBALS['perm'] = $stub;
$this->avatar_id = "123456789";
$this->avatar = Avatar::getAvatar($this->avatar_id);
}
public function test_class_should_exist()
{
$this->assertTrue(class_exists(Avatar::class));
}
protected function getType(): string
{
return 'user';
}
}
class CourseAvatarTestCase extends AvatarTest
{
public function setUp(): void
{
parent::setUp();
$this->avatar_id = "123456789";
$this->avatar = CourseAvatar::getAvatar($this->avatar_id);
}
public function test_class_should_exist()
{
$this->assertTrue(class_exists(CourseAvatar::class));
}
protected function getType(): string
{
return 'course';
}
}
|