BookStack/tests/User/UserProfileTest.php

106 lines
3.7 KiB
PHP
Raw Normal View History

2021-06-26 23:23:15 +08:00
<?php
namespace Tests\User;
use Activity;
use BookStack\Actions\ActivityType;
use BookStack\Auth\User;
use Tests\TestCase;
2016-02-19 03:32:07 +08:00
class UserProfileTest extends TestCase
2016-02-19 03:32:07 +08:00
{
/**
* @var User
*/
2016-02-19 03:32:07 +08:00
protected $user;
protected function setUp(): void
2016-02-19 03:32:07 +08:00
{
parent::setUp();
$this->user = User::all()->last();
2016-02-19 03:32:07 +08:00
}
public function test_profile_page_shows_name()
{
$this->asAdmin()
->get('/user/' . $this->user->slug)
->assertSee($this->user->name);
2016-02-19 03:32:07 +08:00
}
public function test_profile_page_shows_recent_entities()
{
$content = $this->createEntityChainBelongingToUser($this->user, $this->user);
$resp = $this->asAdmin()->get('/user/' . $this->user->slug);
// Check the recently created page is shown
$resp->assertSee($content['page']->name);
// Check the recently created chapter is shown
$resp->assertSee($content['chapter']->name);
// Check the recently created book is shown
$resp->assertSee($content['book']->name);
2016-02-19 03:32:07 +08:00
}
public function test_profile_page_shows_created_content_counts()
{
$newUser = User::factory()->create();
2016-02-19 03:32:07 +08:00
$this->asAdmin()->get('/user/' . $newUser->slug)
->assertSee($newUser->name)
->assertElementContains('#content-counts', '0 Books')
->assertElementContains('#content-counts', '0 Chapters')
->assertElementContains('#content-counts', '0 Pages');
2016-02-19 03:32:07 +08:00
$this->createEntityChainBelongingToUser($newUser, $newUser);
$this->asAdmin()->get('/user/' . $newUser->slug)
->assertSee($newUser->name)
->assertElementContains('#content-counts', '1 Book')
->assertElementContains('#content-counts', '1 Chapter')
->assertElementContains('#content-counts', '1 Page');
2016-02-19 03:32:07 +08:00
}
public function test_profile_page_shows_recent_activity()
{
$newUser = User::factory()->create();
2016-02-19 03:32:07 +08:00
$this->actingAs($newUser);
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
Activity::add(ActivityType::BOOK_UPDATE, $entities['book']);
Activity::add(ActivityType::PAGE_CREATE, $entities['page']);
2016-02-19 03:32:07 +08:00
$this->asAdmin()->get('/user/' . $newUser->slug)
->assertElementContains('#recent-user-activity', 'updated book')
->assertElementContains('#recent-user-activity', 'created page')
->assertElementContains('#recent-user-activity', $entities['page']->name);
2016-02-19 03:32:07 +08:00
}
public function test_user_activity_has_link_leading_to_profile()
2016-02-19 03:32:07 +08:00
{
$newUser = User::factory()->create();
2016-02-19 03:32:07 +08:00
$this->actingAs($newUser);
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
Activity::add(ActivityType::BOOK_UPDATE, $entities['book']);
Activity::add(ActivityType::PAGE_CREATE, $entities['page']);
2016-02-19 03:32:07 +08:00
$linkSelector = '#recent-activity a[href$="/user/' . $newUser->slug . '"]';
$this->asAdmin()->get('/')
->assertElementContains($linkSelector, $newUser->name);
2016-02-19 03:32:07 +08:00
}
public function test_profile_has_search_links_in_created_entity_lists()
{
$user = $this->getEditor();
$resp = $this->actingAs($this->getAdmin())->get('/user/' . $user->slug);
$expectedLinks = [
'/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Apage%7D',
'/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Achapter%7D',
'/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Abook%7D',
'/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Abookshelf%7D',
];
foreach ($expectedLinks as $link) {
$resp->assertElementContains('[href$="' . $link . '"]', 'View All');
}
}
2016-02-19 03:32:07 +08:00
}