Fixed issue with deleted users in page revision list & extended tests to cover.

This commit is contained in:
Dan Brown 2015-12-15 19:53:46 +00:00
parent af33156369
commit 497747e621
3 changed files with 25 additions and 7 deletions

View file

@ -269,7 +269,7 @@ class PageRepo
* @param Page $page
* @return $this
*/
private function saveRevision(Page $page)
public function saveRevision(Page $page)
{
$revision = $this->pageRevision->fill($page->toArray());
$revision->page_id = $page->id;

View file

@ -32,8 +32,12 @@
@foreach($page->revisions as $revision)
<tr>
<td>{{$revision->name}}</td>
<td style="line-height: 0;"><img class="avatar" src="{{ $revision->createdBy->getAvatar(30) }}" alt="{{$revision->createdBy->name}}"></td>
<td> {{$revision->createdBy->name}}</td>
<td style="line-height: 0;">
@if($revision->createdBy)
<img class="avatar" src="{{ $revision->createdBy->getAvatar(30) }}" alt="{{$revision->createdBy->name}}">
@endif
</td>
<td> @if($revision->createdBy) {{$revision->createdBy->name}} @else Deleted User @endif</td>
<td><small>{{$revision->created_at->format('jS F, Y H:i:s')}} ({{$revision->created_at->diffForHumans()}})</small></td>
<td>
<a href="{{$revision->getUrl()}}" target="_blank">Preview</a>

View file

@ -173,26 +173,40 @@ class EntityTest extends TestCase
public function testEntitiesViewableAfterCreatorDeletion()
{
// Create required assets and revisions
$creator = $this->getNewUser();
$updater = $this->getNewUser();
$entities = $this->createEntityChainBelongingToUser($creator, $updater);
$this->actingAs($creator);
app('BookStack\Repos\UserRepo')->destroy($creator);
app('BookStack\Repos\PageRepo')->saveRevision($entities['page']);
$this->asAdmin()->visit($entities['book']->getUrl())->seeStatusCode(200)
->visit($entities['chapter']->getUrl())->seeStatusCode(200)
->visit($entities['page']->getUrl())->seeStatusCode(200);
$this->checkEntitiesViewable($entities);
}
public function testEntitiesViewableAfterUpdaterDeletion()
{
// Create required assets and revisions
$creator = $this->getNewUser();
$updater = $this->getNewUser();
$entities = $this->createEntityChainBelongingToUser($creator, $updater);
$this->actingAs($updater);
app('BookStack\Repos\UserRepo')->destroy($updater);
app('BookStack\Repos\PageRepo')->saveRevision($entities['page']);
$this->asAdmin()->visit($entities['book']->getUrl())->seeStatusCode(200)
$this->checkEntitiesViewable($entities);
}
private function checkEntitiesViewable($entities)
{
// Check pages and books are visible.
$this->asAdmin();
$this->visit($entities['book']->getUrl())->seeStatusCode(200)
->visit($entities['chapter']->getUrl())->seeStatusCode(200)
->visit($entities['page']->getUrl())->seeStatusCode(200);
// Check revision listing shows no errors.
$this->visit($entities['page']->getUrl())
->click('Revisions')->seeStatusCode(200);
}