testShouldReturnUserSkinWithSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MinepicTests\Http\Controllers;
6
7
use Minepic\Cache\UserNotFoundCache;
8
use Minepic\Events\Account\AccountCreatedEvent;
9
use Minepic\Models\Account;
10
use Minepic\Models\AccountStats;
11
use MinepicTests\TestCase;
12
13
class ApiControllerTest extends TestCase
14
{
15
    protected function setUp(): void
16
    {
17
        parent::setUp();
18
        \DB::beginTransaction();
19
        UserNotFoundCache::add('ThisIsAnInvalidAccountName');
20
    }
21
22
    protected function tearDown(): void
23
    {
24
        \DB::rollBack();
25
        parent::tearDown();
26
    }
27
28
    public function testShouldReturnSteveAvatar(): void
29
    {
30
        $this->get('/avatar/ThisIsAnInvalidAccountName');
31
        $actualImage = $this->response->getContent();
32
        $expectedImage = file_get_contents(base_path('tests/images/steve_avatar.png'));
33
        self::assertEquals($expectedImage, $actualImage);
34
    }
35
36
    public function testShouldReturnUserAvatarWithSize(): void
37
    {
38
        $this->get('/avatar/200/_Cyb3r');
39
        $this->assertResponseOk();
40
        self::assertEquals(
41
            'image/png',
42
            $this->response->headers->get('Content-Type')
43
        );
44
    }
45
46
    public function testShouldReturnUserSkinWithoutSize(): void
47
    {
48
        $this->get('/skin/_Cyb3r');
49
        $this->assertResponseOk();
50
        self::assertEquals(
51
            'image/png',
52
            $this->response->headers->get('Content-Type')
53
        );
54
    }
55
56
    public function testShouldReturnUserSkinBackWithoutSize(): void
57
    {
58
        $this->get('/skin-back/_Cyb3r');
59
        $this->assertResponseOk();
60
        self::assertEquals(
61
            'image/png',
62
            $this->response->headers->get('Content-Type')
63
        );
64
    }
65
66
    public function testShouldReturnUserSkinWithSize(): void
67
    {
68
        $this->get('/skin/200/_Cyb3r');
69
        $this->assertResponseOk();
70
        self::assertEquals(
71
            'image/png',
72
            $this->response->headers->get('Content-Type')
73
        );
74
    }
75
76
    public function testShouldReturnUserSkinBackWithSize(): void
77
    {
78
        $this->get('/skin-back/200/_Cyb3r');
79
        $this->assertResponseOk();
80
        self::assertEquals(
81
            'image/png',
82
            $this->response->headers->get('Content-Type')
83
        );
84
    }
85
86
    public function testShouldReturnSteveSkin(): void
87
    {
88
        $this->get('/skin/ThisIsAnInvalidAccountName');
89
        $actualImage = $this->response->getContent();
90
        $expectedImage = file_get_contents(base_path('tests/images/steve_skin.png'));
91
        self::assertEquals($expectedImage, $actualImage);
92
    }
93
94
    public function testShouldReturnSteveSkinBack(): void
95
    {
96
        $this->get('/skin-back/ThisIsAnInvalidAccountName');
97
        $actualImage = $this->response->getContent();
98
        $expectedImage = file_get_contents(base_path('tests/images/steve_skin_back.png'));
99
        self::assertEquals($expectedImage, $actualImage);
100
    }
101
102
    public function testShouldReturnSteveHead(): void
103
    {
104
        $this->get('/head/ThisIsAnInvalidAccountName');
105
        $this->assertResponseOk();
106
        self::assertEquals(
107
            'image/png',
108
            $this->response->headers->get('Content-Type')
109
        );
110
    }
111
112
    public function testShouldDownloadSteveTexture(): void
113
    {
114
        $this->get('/download/00000000000000000000000000000000');
115
        $actualImage = $this->response->getContent();
116
        $expectedImage = file_get_contents(base_path('tests/images/steve_raw.png'));
117
118
        self::assertEquals($expectedImage, $actualImage);
119
    }
120
121
    public function testReturnIsometricAvatar(): void
122
    {
123
        $this->get('/head/d59dcabb30424b978f7201d1a076637f');
124
        $this->assertResponseOk();
125
        self::assertEquals(
126
            'image/png',
127
            $this->response->headers->get('Content-Type')
128
        );
129
    }
130
131
    public function testReturnDefaultIsometricAvatar(): void
132
    {
133
        UserNotFoundCache::add('9bac3f78c4a44f5e841627a674981a5a');
134
        $this->get('/head/9bac3f78c4a44f5e841627a674981a5a');
135
        $this->assertResponseOk();
136
        self::assertEquals(
137
            'image/png',
138
            $this->response->headers->get('Content-Type')
139
        );
140
        /*
141
        $actualImage = $this->response->getContent();
142
        $expectedImage = \file_get_contents(base_path('tests/images/steve_avatar.png'));
143
        self::assertEquals($expectedImage, $actualImage);
144
        */
145
    }
146
147
    public function testReturnAvatarUsingDifferentUuidFormat(): void
148
    {
149
        $this->get('/avatar/d59dcabb-3042-4b97-8f72-01d1a076637f');
150
        $this->assertResponseOk();
151
        self::assertEquals(
152
            'image/png',
153
            $this->response->headers->get('Content-Type')
154
        );
155
    }
156
157
    public function testShouldFailUpdatingUnExistingUser(): void
158
    {
159
        $this->get('/update/d59dcabb30424b978f7201ffffffffff');
160
161
        $expectedStatusCode = 404;
162
        $expectedContentType = 'application/json';
163
        self::assertEquals($expectedContentType, $this->response->headers->get('Content-Type'));
164
        self::assertEquals($expectedStatusCode, $this->response->getStatusCode());
165
    }
166
167
    public function testRetrieveNewUser(): void
168
    {
169
        // Cleanup
170
        $steve = Account::whereUsername('MHF_Steve')->first();
171
        if ($steve !== null) {
172
            AccountStats::whereUuid($steve->uuid)->delete();
173
            $steve->delete();
174
        }
175
176
        $this->expectsEvents(AccountCreatedEvent::class);
177
        $this->get('/avatar/MHF_Steve');
178
179
        $expectedStatusCode = 200;
180
        $expectedContentType = 'image/png';
181
        self::assertEquals($expectedContentType, $this->response->headers->get('Content-Type'));
182
        self::assertEquals($expectedStatusCode, $this->response->getStatusCode());
183
    }
184
}
185