mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-01-03 23:42:28 +03:00
Added maintenance action to regenerate references
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
namespace Tests\Settings;
|
||||
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Bookshelf;
|
||||
@@ -10,6 +10,7 @@ use BookStack\Entities\Models\Entity;
|
||||
use BookStack\Entities\Models\Page;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RecycleBinTest extends TestCase
|
||||
{
|
||||
55
tests/Settings/RegenerateReferencesTest.php
Normal file
55
tests/Settings/RegenerateReferencesTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Settings;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\References\ReferenceStore;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RegenerateReferencesTest extends TestCase
|
||||
{
|
||||
public function test_option_visible_on_maintenance_page()
|
||||
{
|
||||
$pageView = $this->asAdmin()->get('/settings/maintenance');
|
||||
$formCssSelector = 'form[action$="/settings/maintenance/regenerate-references"]';
|
||||
$html = $this->withHtml($pageView);
|
||||
$html->assertElementExists('#regenerate-references');
|
||||
$html->assertElementExists($formCssSelector);
|
||||
$html->assertElementContains($formCssSelector . ' button', 'Regenerate References');
|
||||
}
|
||||
|
||||
public function test_action_runs_reference_regen()
|
||||
{
|
||||
$this->mock(ReferenceStore::class)
|
||||
->shouldReceive('updateForAllPages')
|
||||
->once();
|
||||
|
||||
$resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');
|
||||
$resp->assertRedirect('/settings/maintenance#regenerate-references');
|
||||
$this->assertSessionHas('success', 'Reference index has been regenerated!');
|
||||
$this->assertActivityExists(ActivityType::MAINTENANCE_ACTION_RUN, null, 'regenerate-references');
|
||||
}
|
||||
|
||||
public function test_settings_manage_permission_required()
|
||||
{
|
||||
$editor = $this->getEditor();
|
||||
$resp = $this->actingAs($editor)->post('/settings/maintenance/regenerate-references');
|
||||
$this->assertPermissionError($resp);
|
||||
|
||||
$this->giveUserPermissions($editor, ['settings-manage']);
|
||||
|
||||
$resp = $this->actingAs($editor)->post('/settings/maintenance/regenerate-references');
|
||||
$this->assertNotPermissionError($resp);
|
||||
}
|
||||
|
||||
public function test_action_failed_shown_as_error_notification()
|
||||
{
|
||||
$this->mock(ReferenceStore::class)
|
||||
->shouldReceive('updateForAllPages')
|
||||
->andThrow(\Exception::class, 'A badger stopped the task');
|
||||
|
||||
$resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');
|
||||
$resp->assertRedirect('/settings/maintenance#regenerate-references');
|
||||
$this->assertSessionError('A badger stopped the task');
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
namespace Tests\Settings;
|
||||
|
||||
use BookStack\Notifications\TestEmail;
|
||||
use Illuminate\Contracts\Notifications\Dispatcher;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TestEmailTest extends TestCase
|
||||
{
|
||||
Reference in New Issue
Block a user