Skip to content

Commit

Permalink
Use setting method
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed Apr 28, 2021
1 parent b1cc65a commit b5197ae
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ protected function setUp(): void
$this->prepareDatabase([
'api_keys' => [
['user_id' => 1, 'key' => 'superadmin'],
],
'settings' => [
['key' => 'csrf_test', 'value' => 1],
],
]
]);

$this->setting('csrf_test', 1);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions tests/integration/api/users/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ protected function setUp(): void
{
parent::setUp();

$this->prepareDatabase([
'settings' => [
['key' => 'mail_driver', 'value' => 'log'],
],
]);
$this->setting('mail_driver', 'log');
}

/**
Expand Down
12 changes: 3 additions & 9 deletions tests/integration/extenders/ModelUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
use Flarum\Http\SlugManager;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\Testing\integration\UsesSettings;
use Flarum\User\User;

class ModelUrlTest extends TestCase
{
use RetrievesAuthorizedUsers;
use UsesSettings;

/**
* @inheritDoc
Expand All @@ -31,12 +29,12 @@ protected function setUp(): void
parent::setUp();

$userClass = User::class;

$this->setting("slug_driver_$userClass", 'testDriver');

$this->prepareDatabase([
'users' => [
$this->normalUser(),
],
'settings' => [
['key' => "slug_driver_$userClass", 'value' => 'testDriver'],
]
]);
}
Expand All @@ -46,8 +44,6 @@ protected function setUp(): void
*/
public function uses_default_driver_by_default()
{
$this->purgeSettingsCache();

$slugManager = $this->app()->getContainer()->make(SlugManager::class);

$testUser = User::find(1);
Expand All @@ -63,8 +59,6 @@ public function custom_slug_driver_has_effect_if_added()
{
$this->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class));

$this->purgeSettingsCache();

$slugManager = $this->app()->getContainer()->make(SlugManager::class);

$testUser = User::find(1);
Expand Down
21 changes: 3 additions & 18 deletions tests/integration/extenders/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
use Flarum\Extend;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\Testing\integration\UsesSettings;

class SettingsTest extends TestCase
{
use RetrievesAuthorizedUsers;
use UsesSettings;

/**
* @inheritDoc
Expand All @@ -29,21 +27,18 @@ protected function setUp(): void
$this->prepareDatabase([
'users' => [
$this->normalUser()
],
'settings' => [
['key' => 'custom-prefix.custom_setting', 'value' => 'customValue'],
['key' => 'custom-prefix.custom_setting2', 'value' => 'customValue']
]
]);

$this->setting('custom-prefix.custom_setting', 'customValue');
$this->setting('custom-prefix.custom_setting2', 'customValue');
}

/**
* @test
*/
public function custom_setting_isnt_serialized_by_default()
{
$this->purgeSettingsCache();

$response = $this->send(
$this->request('GET', '/api', [
'authenticatedAs' => 1,
Expand All @@ -65,8 +60,6 @@ public function custom_setting_serialized_if_added()
->serializeToForum('customPrefix.customSetting', 'custom-prefix.custom_setting')
);

$this->purgeSettingsCache();

$response = $this->send(
$this->request('GET', '/api', [
'authenticatedAs' => 1,
Expand All @@ -91,8 +84,6 @@ public function custom_setting_callback_works_if_added()
})
);

$this->purgeSettingsCache();

$response = $this->send(
$this->request('GET', '/api', [
'authenticatedAs' => 1,
Expand All @@ -115,8 +106,6 @@ public function custom_setting_callback_works_with_invokable_class()
->serializeToForum('customPrefix.customSetting2', 'custom-prefix.custom_setting2', CustomInvokableClass::class)
);

$this->purgeSettingsCache();

$response = $this->send(
$this->request('GET', '/api', [
'authenticatedAs' => 1,
Expand All @@ -139,8 +128,6 @@ public function custom_setting_falls_back_to_default()
->serializeToForum('customPrefix.noCustomSetting', 'custom-prefix.no_custom_setting', null, 'customDefault')
);

$this->purgeSettingsCache();

$response = $this->send(
$this->request('GET', '/api', [
'authenticatedAs' => 1,
Expand All @@ -165,8 +152,6 @@ public function custom_setting_default_passed_to_callback()
}, 'customDefault')
);

$this->purgeSettingsCache();

$response = $this->send(
$this->request('GET', '/api', [
'authenticatedAs' => 1,
Expand Down
18 changes: 1 addition & 17 deletions tests/integration/extenders/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
use Flarum\Extend;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Flarum\Testing\integration\UsesSettings;
use Flarum\User\DisplayName\DriverInterface;
use Flarum\User\User;
use Illuminate\Support\Arr;

class UserTest extends TestCase
{
use RetrievesAuthorizedUsers;
use UsesSettings;

/**
* @inheritDoc
Expand All @@ -32,22 +30,10 @@ protected function setUp(): void
$this->prepareDatabase([
'users' => [
$this->normalUser(),
],
'settings' => [
['key' => 'display_name_driver', 'value' => 'custom'],
]
]);
}

/**
* Purge the settings cache and reset the new display name driver.
*/
protected function recalculateDisplayNameDriver()
{
$this->purgeSettingsCache();
$container = $this->app()->getContainer();
$container->forgetInstance('flarum.user.display_name.driver');
User::setDisplayNameDriver($container->make('flarum.user.display_name.driver'));
$this->setting('display_name_driver', 'custom');
}

protected function registerTestPreference()
Expand All @@ -64,7 +50,6 @@ protected function registerTestPreference()
public function username_display_name_driver_used_by_default()
{
$this->app();
$this->recalculateDisplayNameDriver();

$user = User::find(1);

Expand All @@ -82,7 +67,6 @@ public function can_use_custom_display_name_driver()
);

$this->app();
$this->recalculateDisplayNameDriver();

$user = User::find(1);

Expand Down

0 comments on commit b5197ae

Please sign in to comment.