1
0
mirror of https://github.com/flarum/core.git synced 2025-08-12 03:14:33 +02:00
- split up deprecated and remaining user notification logic
- started building a test (needs work)
- created new Model for NotificationPreference
- created extender to register a NotificationChannel
- created extender to maintain UserPreferences

User preferences are still possible on the users table directly.
Registering a user preference allows for transformation to happen.
And provides easier accessors. Not sure we want this.

! tests need work.
This commit is contained in:
Daniël Klabbers
2020-03-24 10:58:28 +01:00
parent 49d8559599
commit 46e049ecb0
7 changed files with 182 additions and 11 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Flarum\Tests\integration\extenders;
use Flarum\Extend\NotificationChannel;
use Flarum\Extend\UserPreferences;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
use Flarum\User\User;
use Illuminate\Support\Arr;
class NotificationChannelTest extends TestCase
{
use RetrievesAuthorizedUsers;
public function setUp()
{
parent::setUp();
$this->prepareDatabase([
'users' => [
$this->normalUser()
]
]);
}
private function add_channel()
{
$this->extend(new NotificationChannel('test'));
}
/**
* @test
*/
public function can_add_notification_channel()
{
$this->add_channel();
/** @var User $user */
$user = User::find(2);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Flarum\Tests\integration\extenders;
use Flarum\Extend\UserPreferences;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
use Flarum\User\User;
use Illuminate\Support\Arr;
class UserPreferencesTest extends TestCase
{
use RetrievesAuthorizedUsers;
public function setUp()
{
parent::setUp();
$this->prepareDatabase([
'users' => [
$this->normalUser()
]
]);
}
private function add_preference()
{
$this->extend(
(new UserPreferences())
->add('test', 'boolval', false)
);
}
/**
* @test
*/
public function can_add_user_preference()
{
$this->add_preference();
/** @var User $user */
$user = User::find(2);
$this->assertEquals(false, Arr::get($user->preferences, 'test'));
}
/**
* @test
*/
public function can_store_user_preference()
{
$this->add_preference();
/** @var User $user */
$user = User::find(2);
$user->setPreference('test', true);
$this->assertEquals(true, $user->test);
}
}