Skip to content

Commit 86c5d01

Browse files
committed
chore: add test
1 parent c6b348d commit 86c5d01

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Flarum.
5+
*
6+
* For detailed copyright and license information, please view the
7+
* LICENSE file that was distributed with this source code.
8+
*/
9+
10+
namespace Flarum\Tests\integration\api\info;
11+
12+
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
13+
use Flarum\Testing\integration\TestCase;
14+
use Illuminate\Support\Arr;
15+
16+
class ShowTest extends TestCase
17+
{
18+
use RetrievesAuthorizedUsers;
19+
20+
/**
21+
* @inheritDoc
22+
*/
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
27+
$this->prepareDatabase([
28+
'users' => [
29+
$this->normalUser(),
30+
]
31+
]);
32+
}
33+
34+
/**
35+
* @test
36+
*/
37+
public function guest_cannot_access_system_info()
38+
{
39+
$response = $this->send(
40+
$this->request('GET', '/api/info')
41+
);
42+
43+
$this->assertEquals(401, $response->getStatusCode());
44+
}
45+
46+
/**
47+
* @test
48+
*/
49+
public function normal_user_cannot_access_system_info()
50+
{
51+
$response = $this->send(
52+
$this->request('GET', '/api/info', [
53+
'authenticatedAs' => 2,
54+
])
55+
);
56+
57+
$this->assertEquals(403, $response->getStatusCode());
58+
}
59+
60+
/**
61+
* @test
62+
*/
63+
public function admin_can_access_system_info()
64+
{
65+
$response = $this->send(
66+
$this->request('GET', '/api/info', [
67+
'authenticatedAs' => 1,
68+
])
69+
);
70+
71+
$this->assertEquals(200, $response->getStatusCode());
72+
73+
$json = json_decode($response->getBody()->getContents(), true);
74+
75+
// Check that we have the expected structure
76+
$this->assertEquals('system-info', Arr::get($json, 'data.type'));
77+
$this->assertEquals('system', Arr::get($json, 'data.id'));
78+
$this->assertArrayHasKey('content', Arr::get($json, 'data.attributes'));
79+
80+
// Check that the content contains expected info
81+
$content = Arr::get($json, 'data.attributes.content');
82+
$this->assertIsString($content);
83+
$this->assertStringContainsString('Flarum core:', $content);
84+
$this->assertStringContainsString('PHP version:', $content);
85+
}
86+
}

0 commit comments

Comments
 (0)