mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-30 07:32:39 +01:00
Notifications: Switched testing from string to reference levels
This commit is contained in:
parent
38829f8a38
commit
e709caa005
@ -23,7 +23,7 @@ class WatchController extends Controller
|
|||||||
|
|
||||||
$watchable = $this->getValidatedModelFromRequest($request);
|
$watchable = $this->getValidatedModelFromRequest($request);
|
||||||
$watchOptions = new UserEntityWatchOptions(user(), $watchable);
|
$watchOptions = new UserEntityWatchOptions(user(), $watchable);
|
||||||
$watchOptions->updateWatchLevel($requestData['level']);
|
$watchOptions->updateLevelByName($requestData['level']);
|
||||||
|
|
||||||
$this->showSuccessNotification(trans('activities.watch_update_level_notification'));
|
$this->showSuccessNotification(trans('activities.watch_update_level_notification'));
|
||||||
|
|
||||||
|
@ -51,15 +51,20 @@ class UserEntityWatchOptions
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateWatchLevel(string $level): void
|
public function updateLevelByName(string $level): void
|
||||||
{
|
{
|
||||||
$levelValue = WatchLevels::levelNameToValue($level);
|
$levelValue = WatchLevels::levelNameToValue($level);
|
||||||
if ($levelValue < 0) {
|
$this->updateLevelByValue($levelValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateLevelByValue(int $level): void
|
||||||
|
{
|
||||||
|
if ($level < 0) {
|
||||||
$this->remove();
|
$this->remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->updateLevel($levelValue);
|
$this->updateLevel($level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWatchMap(): array
|
public function getWatchMap(): array
|
||||||
|
@ -26,7 +26,7 @@ class WatchTest extends TestCase
|
|||||||
$this->withHtml($resp)->assertElementContains('form[action$="/watching/update"] button.icon-list-item', 'Watch');
|
$this->withHtml($resp)->assertElementContains('form[action$="/watching/update"] button.icon-list-item', 'Watch');
|
||||||
|
|
||||||
$watchOptions = new UserEntityWatchOptions($editor, $entity);
|
$watchOptions = new UserEntityWatchOptions($editor, $entity);
|
||||||
$watchOptions->updateWatchLevel('comments');
|
$watchOptions->updateLevelByValue(WatchLevels::COMMENTS);
|
||||||
|
|
||||||
$resp = $this->get($entity->getUrl());
|
$resp = $this->get($entity->getUrl());
|
||||||
$this->withHtml($resp)->assertElementNotExists('form[action$="/watching/update"] button.icon-list-item');
|
$this->withHtml($resp)->assertElementNotExists('form[action$="/watching/update"] button.icon-list-item');
|
||||||
@ -112,17 +112,17 @@ class WatchTest extends TestCase
|
|||||||
$chapter = $book->chapters()->first();
|
$chapter = $book->chapters()->first();
|
||||||
$page = $chapter->pages()->first();
|
$page = $chapter->pages()->first();
|
||||||
|
|
||||||
(new UserEntityWatchOptions($editor, $book))->updateWatchLevel('updates');
|
(new UserEntityWatchOptions($editor, $book))->updateLevelByValue(WatchLevels::UPDATES);
|
||||||
|
|
||||||
$this->actingAs($editor)->get($book->getUrl())->assertSee('Watching new pages and updates');
|
$this->actingAs($editor)->get($book->getUrl())->assertSee('Watching new pages and updates');
|
||||||
$this->get($chapter->getUrl())->assertSee('Watching via parent book');
|
$this->get($chapter->getUrl())->assertSee('Watching via parent book');
|
||||||
$this->get($page->getUrl())->assertSee('Watching via parent book');
|
$this->get($page->getUrl())->assertSee('Watching via parent book');
|
||||||
|
|
||||||
(new UserEntityWatchOptions($editor, $chapter))->updateWatchLevel('comments');
|
(new UserEntityWatchOptions($editor, $chapter))->updateLevelByValue(WatchLevels::COMMENTS);
|
||||||
$this->get($chapter->getUrl())->assertSee('Watching new pages, updates & comments');
|
$this->get($chapter->getUrl())->assertSee('Watching new pages, updates & comments');
|
||||||
$this->get($page->getUrl())->assertSee('Watching via parent chapter');
|
$this->get($page->getUrl())->assertSee('Watching via parent chapter');
|
||||||
|
|
||||||
(new UserEntityWatchOptions($editor, $page))->updateWatchLevel('updates');
|
(new UserEntityWatchOptions($editor, $page))->updateLevelByValue(WatchLevels::UPDATES);
|
||||||
$this->get($page->getUrl())->assertSee('Watching new pages and updates');
|
$this->get($page->getUrl())->assertSee('Watching new pages and updates');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ class WatchTest extends TestCase
|
|||||||
{
|
{
|
||||||
$editor = $this->users->editor();
|
$editor = $this->users->editor();
|
||||||
$book = $this->entities->bookHasChaptersAndPages();
|
$book = $this->entities->bookHasChaptersAndPages();
|
||||||
(new UserEntityWatchOptions($editor, $book))->updateWatchLevel('ignore');
|
(new UserEntityWatchOptions($editor, $book))->updateLevelByValue(WatchLevels::IGNORE);
|
||||||
|
|
||||||
$this->actingAs($editor)->get($book->getUrl())->assertSee('Ignoring notifications');
|
$this->actingAs($editor)->get($book->getUrl())->assertSee('Ignoring notifications');
|
||||||
$this->get($book->chapters()->first()->getUrl())->assertSee('Ignoring via parent book');
|
$this->get($book->chapters()->first()->getUrl())->assertSee('Ignoring via parent book');
|
||||||
@ -146,11 +146,11 @@ class WatchTest extends TestCase
|
|||||||
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
||||||
$respHtml->assertElementNotExists('form[action$="/watching/update"] svg[data-icon="check-circle"]');
|
$respHtml->assertElementNotExists('form[action$="/watching/update"] svg[data-icon="check-circle"]');
|
||||||
|
|
||||||
$options->updateWatchLevel('comments');
|
$options->updateLevelByValue(WatchLevels::COMMENTS);
|
||||||
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
||||||
$respHtml->assertElementExists('form[action$="/watching/update"] button[value="comments"] svg[data-icon="check-circle"]');
|
$respHtml->assertElementExists('form[action$="/watching/update"] button[value="comments"] svg[data-icon="check-circle"]');
|
||||||
|
|
||||||
$options->updateWatchLevel('ignore');
|
$options->updateLevelByValue(WatchLevels::IGNORE);
|
||||||
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
||||||
$respHtml->assertElementExists('form[action$="/watching/update"] button[value="ignore"] svg[data-icon="check-circle"]');
|
$respHtml->assertElementExists('form[action$="/watching/update"] button[value="ignore"] svg[data-icon="check-circle"]');
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ class WatchTest extends TestCase
|
|||||||
{
|
{
|
||||||
$editor = $this->users->editor();
|
$editor = $this->users->editor();
|
||||||
$book = $this->entities->bookHasChaptersAndPages();
|
$book = $this->entities->bookHasChaptersAndPages();
|
||||||
(new UserEntityWatchOptions($editor, $book))->updateWatchLevel('ignore');
|
(new UserEntityWatchOptions($editor, $book))->updateLevelByValue(WatchLevels::IGNORE);
|
||||||
|
|
||||||
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
$respHtml = $this->withHtml($this->actingAs($editor)->get($book->getUrl()));
|
||||||
$respHtml->assertElementExists('form[action$="/watching/update"] button[name="level"][value="new"]');
|
$respHtml->assertElementExists('form[action$="/watching/update"] button[name="level"][value="new"]');
|
||||||
@ -225,7 +225,7 @@ class WatchTest extends TestCase
|
|||||||
$entities = $this->entities->createChainBelongingToUser($editor);
|
$entities = $this->entities->createChainBelongingToUser($editor);
|
||||||
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
||||||
$prefs = new UserNotificationPreferences($editor);
|
$prefs = new UserNotificationPreferences($editor);
|
||||||
$watches->updateWatchLevel('ignore');
|
$watches->updateLevelByValue(WatchLevels::IGNORE);
|
||||||
$prefs->updateFromSettingsArray(['own-page-changes' => 'true', 'own-page-comments' => true]);
|
$prefs->updateFromSettingsArray(['own-page-changes' => 'true', 'own-page-comments' => true]);
|
||||||
|
|
||||||
$notifications = Notification::fake();
|
$notifications = Notification::fake();
|
||||||
@ -244,7 +244,7 @@ class WatchTest extends TestCase
|
|||||||
$admin = $this->users->admin();
|
$admin = $this->users->admin();
|
||||||
$entities = $this->entities->createChainBelongingToUser($editor);
|
$entities = $this->entities->createChainBelongingToUser($editor);
|
||||||
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
||||||
$watches->updateWatchLevel('comments');
|
$watches->updateLevelByValue(WatchLevels::COMMENTS);
|
||||||
|
|
||||||
// Comment post
|
// Comment post
|
||||||
$this->actingAs($admin)->post("/comment/{$entities['page']->id}", [
|
$this->actingAs($admin)->post("/comment/{$entities['page']->id}", [
|
||||||
@ -269,7 +269,7 @@ class WatchTest extends TestCase
|
|||||||
$admin = $this->users->admin();
|
$admin = $this->users->admin();
|
||||||
$entities = $this->entities->createChainBelongingToUser($editor);
|
$entities = $this->entities->createChainBelongingToUser($editor);
|
||||||
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
||||||
$watches->updateWatchLevel('updates');
|
$watches->updateLevelByValue(WatchLevels::UPDATES);
|
||||||
|
|
||||||
$this->actingAs($admin);
|
$this->actingAs($admin);
|
||||||
$this->entities->updatePage($entities['page'], ['name' => 'Updated page', 'html' => 'new page content']);
|
$this->entities->updatePage($entities['page'], ['name' => 'Updated page', 'html' => 'new page content']);
|
||||||
@ -297,7 +297,7 @@ class WatchTest extends TestCase
|
|||||||
$admin = $this->users->admin();
|
$admin = $this->users->admin();
|
||||||
$entities = $this->entities->createChainBelongingToUser($editor);
|
$entities = $this->entities->createChainBelongingToUser($editor);
|
||||||
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
$watches = new UserEntityWatchOptions($editor, $entities['book']);
|
||||||
$watches->updateWatchLevel('new');
|
$watches->updateLevelByValue(WatchLevels::NEW);
|
||||||
|
|
||||||
$this->actingAs($admin)->get($entities['chapter']->getUrl('/create-page'));
|
$this->actingAs($admin)->get($entities['chapter']->getUrl('/create-page'));
|
||||||
$page = $entities['chapter']->pages()->where('draft', '=', true)->first();
|
$page = $entities['chapter']->pages()->where('draft', '=', true)->first();
|
||||||
@ -320,7 +320,7 @@ class WatchTest extends TestCase
|
|||||||
$page = $this->entities->page();
|
$page = $this->entities->page();
|
||||||
|
|
||||||
$watches = new UserEntityWatchOptions($editor, $page);
|
$watches = new UserEntityWatchOptions($editor, $page);
|
||||||
$watches->updateWatchLevel('comments');
|
$watches->updateLevelByValue(WatchLevels::COMMENTS);
|
||||||
$this->permissions->disableEntityInheritedPermissions($page);
|
$this->permissions->disableEntityInheritedPermissions($page);
|
||||||
|
|
||||||
$this->asAdmin()->post("/comment/{$page->id}", [
|
$this->asAdmin()->post("/comment/{$page->id}", [
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Tests\User;
|
namespace Tests\User;
|
||||||
|
|
||||||
use BookStack\Activity\Tools\UserEntityWatchOptions;
|
use BookStack\Activity\Tools\UserEntityWatchOptions;
|
||||||
|
use BookStack\Activity\WatchLevels;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UserPreferencesTest extends TestCase
|
class UserPreferencesTest extends TestCase
|
||||||
@ -110,13 +111,13 @@ class UserPreferencesTest extends TestCase
|
|||||||
$book = $this->entities->book();
|
$book = $this->entities->book();
|
||||||
|
|
||||||
$options = new UserEntityWatchOptions($editor, $book);
|
$options = new UserEntityWatchOptions($editor, $book);
|
||||||
$options->updateWatchLevel('comments');
|
$options->updateLevelByValue(WatchLevels::COMMENTS);
|
||||||
|
|
||||||
$resp = $this->actingAs($editor)->get('/preferences/notifications');
|
$resp = $this->actingAs($editor)->get('/preferences/notifications');
|
||||||
$resp->assertSee($book->name);
|
$resp->assertSee($book->name);
|
||||||
$resp->assertSee('All Page Updates & Comments');
|
$resp->assertSee('All Page Updates & Comments');
|
||||||
|
|
||||||
$options->updateWatchLevel('default');
|
$options->updateLevelByValue(WatchLevels::DEFAULT);
|
||||||
|
|
||||||
$resp = $this->actingAs($editor)->get('/preferences/notifications');
|
$resp = $this->actingAs($editor)->get('/preferences/notifications');
|
||||||
$resp->assertDontSee($book->name);
|
$resp->assertDontSee($book->name);
|
||||||
|
Loading…
Reference in New Issue
Block a user