mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 07:42:48 +08:00
Add integration tests for settings API endpoint
This commit is contained in:
parent
6d4c7d15a6
commit
28d6471877
|
@ -13,11 +13,6 @@ use Flarum\Foundation\AbstractValidator;
|
|||
|
||||
class SettingsValidator extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $rules = [];
|
||||
|
||||
/**
|
||||
* These rules apply to all attributes.
|
||||
*
|
||||
|
@ -45,9 +40,7 @@ class SettingsValidator extends AbstractValidator
|
|||
|
||||
// Apply attribute specific rules.
|
||||
foreach ($rules as $key => $value) {
|
||||
if (array_key_exists($key, $this->rules)) {
|
||||
$rules[$key] = array_merge($rules[$key], $this->rules[$key]);
|
||||
}
|
||||
$rules[$key] = array_merge($rules[$key], $this->rules[$key] ?? []);
|
||||
}
|
||||
|
||||
$validator = $this->validator->make($attributes, $rules, $this->getMessages());
|
||||
|
|
86
framework/core/tests/integration/api/settings/SetTest.php
Normal file
86
framework/core/tests/integration/api/settings/SetTest.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration\api\settings;
|
||||
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class SetTest extends TestCase
|
||||
{
|
||||
use RetrievesAuthorizedUsers;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->prepareDatabase([
|
||||
'users' => [
|
||||
$this->normalUser(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function settings_cant_be_updated_by_user()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/settings', [
|
||||
'authenticatedAs' => 2,
|
||||
'json' => [
|
||||
'hello' => 'world',
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
// Test for successful response and that the email is included in the response
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function settings_can_be_updated_by_admin()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/settings', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [
|
||||
'hello' => 'world',
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
// Test for successful response and that the email is included in the response
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function max_setting_length_validated()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/settings', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [
|
||||
'hello' => str_repeat('a', 66000),
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
// Test for successful response and that the email is included in the response
|
||||
$this->assertEquals(422, $response->getStatusCode());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user