2022-08-29 12:30:26 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Settings;
|
|
|
|
|
2023-05-17 12:56:55 -04:00
|
|
|
use BookStack\Activity\ActivityType;
|
2022-08-29 12:30:26 -04:00
|
|
|
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)
|
2023-12-20 12:21:09 -05:00
|
|
|
->shouldReceive('updateForAll')
|
2022-08-29 12:30:26 -04:00
|
|
|
->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()
|
|
|
|
{
|
2023-01-21 06:08:34 -05:00
|
|
|
$editor = $this->users->editor();
|
2022-08-29 12:30:26 -04:00
|
|
|
$resp = $this->actingAs($editor)->post('/settings/maintenance/regenerate-references');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
|
2023-01-21 06:08:34 -05:00
|
|
|
$this->permissions->grantUserRolePermissions($editor, ['settings-manage']);
|
2022-08-29 12:30:26 -04:00
|
|
|
|
|
|
|
$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)
|
2023-12-20 12:21:09 -05:00
|
|
|
->shouldReceive('updateForAll')
|
2022-08-29 12:30:26 -04:00
|
|
|
->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');
|
|
|
|
}
|
|
|
|
}
|