Updated testing for user slugs

This commit is contained in:
Dan Brown 2021-03-10 23:04:18 +00:00
parent da929d5edc
commit 3c57cbc567
3 changed files with 19 additions and 10 deletions

View File

@ -9,6 +9,7 @@ use BookStack\Settings\SettingService;
use DB;
use Hash;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
use Tests\BrowserKitTest;
class AuthTest extends BrowserKitTest
@ -221,6 +222,7 @@ class AuthTest extends BrowserKitTest
public function test_user_creation()
{
/** @var User $user */
$user = factory(User::class)->make();
$adminRole = Role::getRole('admin');
@ -234,8 +236,11 @@ class AuthTest extends BrowserKitTest
->type($user->password, '#password-confirm')
->press('Save')
->seePageIs('/settings/users')
->seeInDatabase('users', $user->toArray())
->seeInDatabase('users', $user->only(['name', 'email']))
->see($user->name);
$user->refresh();
$this->assertStringStartsWith(Str::slug($user->name), $user->slug);
}
public function test_user_updating()
@ -252,6 +257,9 @@ class AuthTest extends BrowserKitTest
->seePageIs('/settings/users')
->seeInDatabase('users', ['id' => $user->id, 'name' => 'Barry Scott', 'password' => $password])
->notSeeInDatabase('users', ['name' => $user->name]);
$user->refresh();
$this->assertStringStartsWith(Str::slug($user->name), $user->slug);
}
public function test_user_password_update()

View File

@ -122,6 +122,7 @@ class EntitySearchTest extends TestCase
$page = $this->newPage(['name' => 'My new test quaffleachits', 'html' => 'this is about an orange donkey danzorbhsing']);
$this->asEditor();
$editorId = $this->getEditor()->id;
$editorSlug = $this->getEditor()->slug;
// Viewed filter searches
$this->get('/search?term=' . urlencode('danzorbhsing {not_viewed_by_me}'))->assertSee($page->name);
@ -133,16 +134,16 @@ class EntitySearchTest extends TestCase
// User filters
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertDontSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertDontSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:'.$editorId.'}'))->assertDontSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by: '.$editorSlug.'}'))->assertDontSee($page->name);
$page->created_by = $editorId;
$page->save();
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:'.$editorId.'}'))->assertSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {created_by: '.$editorSlug.'}'))->assertSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertDontSee($page->name);
$page->updated_by = $editorId;
$page->save();
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:'.$editorId.'}'))->assertSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by: '.$editorSlug.'}'))->assertSee($page->name);
// Content filters
$this->get('/search?term=' . urlencode('{in_name:danzorbhsing}'))->assertDontSee($page->name);

View File

@ -19,7 +19,7 @@ class UserProfileTest extends BrowserKitTest
public function test_profile_page_shows_name()
{
$this->asAdmin()
->visit('/user/' . $this->user->id)
->visit('/user/' . $this->user->slug)
->see($this->user->name);
}
@ -28,7 +28,7 @@ class UserProfileTest extends BrowserKitTest
$content = $this->createEntityChainBelongingToUser($this->user, $this->user);
$this->asAdmin()
->visit('/user/' . $this->user->id)
->visit('/user/' . $this->user->slug)
// Check the recently created page is shown
->see($content['page']->name)
// Check the recently created chapter is shown
@ -41,7 +41,7 @@ class UserProfileTest extends BrowserKitTest
{
$newUser = $this->getNewBlankUser();
$this->asAdmin()->visit('/user/' . $newUser->id)
$this->asAdmin()->visit('/user/' . $newUser->slug)
->see($newUser->name)
->seeInElement('#content-counts', '0 Books')
->seeInElement('#content-counts', '0 Chapters')
@ -49,7 +49,7 @@ class UserProfileTest extends BrowserKitTest
$this->createEntityChainBelongingToUser($newUser, $newUser);
$this->asAdmin()->visit('/user/' . $newUser->id)
$this->asAdmin()->visit('/user/' . $newUser->slug)
->see($newUser->name)
->seeInElement('#content-counts', '1 Book')
->seeInElement('#content-counts', '1 Chapter')
@ -64,7 +64,7 @@ class UserProfileTest extends BrowserKitTest
Activity::addForEntity($entities['book'], ActivityType::BOOK_UPDATE);
Activity::addForEntity($entities['page'], ActivityType::PAGE_CREATE);
$this->asAdmin()->visit('/user/' . $newUser->id)
$this->asAdmin()->visit('/user/' . $newUser->slug)
->seeInElement('#recent-user-activity', 'updated book')
->seeInElement('#recent-user-activity', 'created page')
->seeInElement('#recent-user-activity', $entities['page']->name);
@ -79,7 +79,7 @@ class UserProfileTest extends BrowserKitTest
Activity::addForEntity($entities['page'], ActivityType::PAGE_CREATE);
$this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
->seePageIs('/user/' . $newUser->id)
->seePageIs('/user/' . $newUser->slug)
->see($newUser->name);
}