3 namespace Tests\Settings;
5 use BookStack\Activity\ActivityType;
6 use BookStack\References\ReferenceStore;
9 class RegenerateReferencesTest extends TestCase
11 public function test_option_visible_on_maintenance_page()
13 $pageView = $this->asAdmin()->get('/settings/maintenance');
14 $formCssSelector = 'form[action$="/settings/maintenance/regenerate-references"]';
15 $html = $this->withHtml($pageView);
16 $html->assertElementExists('#regenerate-references');
17 $html->assertElementExists($formCssSelector);
18 $html->assertElementContains($formCssSelector . ' button', 'Regenerate References');
21 public function test_action_runs_reference_regen()
23 $this->mock(ReferenceStore::class)
24 ->shouldReceive('updateForAll')
27 $resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');
28 $resp->assertRedirect('/settings/maintenance#regenerate-references');
29 $this->assertSessionHas('success', 'Reference index has been regenerated!');
30 $this->assertActivityExists(ActivityType::MAINTENANCE_ACTION_RUN, null, 'regenerate-references');
33 public function test_settings_manage_permission_required()
35 $editor = $this->users->editor();
36 $resp = $this->actingAs($editor)->post('/settings/maintenance/regenerate-references');
37 $this->assertPermissionError($resp);
39 $this->permissions->grantUserRolePermissions($editor, ['settings-manage']);
41 $resp = $this->actingAs($editor)->post('/settings/maintenance/regenerate-references');
42 $this->assertNotPermissionError($resp);
45 public function test_action_failed_shown_as_error_notification()
47 $this->mock(ReferenceStore::class)
48 ->shouldReceive('updateForAll')
49 ->andThrow(\Exception::class, 'A badger stopped the task');
51 $resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');
52 $resp->assertRedirect('/settings/maintenance#regenerate-references');
53 $this->assertSessionError('A badger stopped the task');