2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\User;
|
2020-04-03 20:16:05 -04:00
|
|
|
|
2020-04-10 07:49:16 -04:00
|
|
|
use Activity;
|
2020-11-07 17:37:27 -05:00
|
|
|
use BookStack\Actions\ActivityType;
|
2020-04-10 07:49:16 -04:00
|
|
|
use BookStack\Auth\User;
|
2021-09-13 17:54:21 -04:00
|
|
|
use Tests\TestCase;
|
2016-02-18 14:32:07 -05:00
|
|
|
|
2021-09-13 17:54:21 -04:00
|
|
|
class UserProfileTest extends TestCase
|
2016-02-18 14:32:07 -05:00
|
|
|
{
|
2021-09-13 17:54:21 -04:00
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
2016-02-18 14:32:07 -05:00
|
|
|
protected $user;
|
|
|
|
|
2019-09-13 18:58:40 -04:00
|
|
|
public function setUp(): void
|
2016-02-18 14:32:07 -05:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-04-10 07:49:16 -04:00
|
|
|
$this->user = User::all()->last();
|
2016-02-18 14:32:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_profile_page_shows_name()
|
|
|
|
{
|
|
|
|
$this->asAdmin()
|
2021-09-13 17:54:21 -04:00
|
|
|
->get('/user/' . $this->user->slug)
|
|
|
|
->assertSee($this->user->name);
|
2016-02-18 14:32:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_profile_page_shows_recent_entities()
|
|
|
|
{
|
|
|
|
$content = $this->createEntityChainBelongingToUser($this->user, $this->user);
|
|
|
|
|
2021-09-13 17:54:21 -04:00
|
|
|
$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-18 14:32:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_profile_page_shows_created_content_counts()
|
|
|
|
{
|
2021-09-13 17:54:21 -04:00
|
|
|
$newUser = factory(User::class)->create();
|
2016-02-18 14:32:07 -05:00
|
|
|
|
2021-09-13 17:54:21 -04: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-18 14:32:07 -05:00
|
|
|
|
|
|
|
$this->createEntityChainBelongingToUser($newUser, $newUser);
|
|
|
|
|
2021-09-13 17:54:21 -04:00
|
|
|
$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-18 14:32:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_profile_page_shows_recent_activity()
|
|
|
|
{
|
2021-09-13 17:54:21 -04:00
|
|
|
$newUser = factory(User::class)->create();
|
2016-02-18 14:32:07 -05:00
|
|
|
$this->actingAs($newUser);
|
|
|
|
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
|
2020-11-07 18:15:13 -05:00
|
|
|
Activity::addForEntity($entities['book'], ActivityType::BOOK_UPDATE);
|
|
|
|
Activity::addForEntity($entities['page'], ActivityType::PAGE_CREATE);
|
2016-02-18 14:32:07 -05:00
|
|
|
|
2021-09-13 17:54:21 -04: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-18 14:32:07 -05:00
|
|
|
}
|
|
|
|
|
2021-09-13 17:54:21 -04:00
|
|
|
public function test_user_activity_has_link_leading_to_profile()
|
2016-02-18 14:32:07 -05:00
|
|
|
{
|
2021-09-13 17:54:21 -04:00
|
|
|
$newUser = factory(User::class)->create();
|
2016-02-18 14:32:07 -05:00
|
|
|
$this->actingAs($newUser);
|
|
|
|
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
|
2020-11-07 18:15:13 -05:00
|
|
|
Activity::addForEntity($entities['book'], ActivityType::BOOK_UPDATE);
|
|
|
|
Activity::addForEntity($entities['page'], ActivityType::PAGE_CREATE);
|
2016-02-18 14:32:07 -05:00
|
|
|
|
2021-09-13 17:54:21 -04:00
|
|
|
$linkSelector = '#recent-activity a[href$="/user/' . $newUser->slug . '"]';
|
|
|
|
$this->asAdmin()->get('/')
|
|
|
|
->assertElementContains($linkSelector, $newUser->name);
|
2016-02-18 14:32:07 -05:00
|
|
|
}
|
2016-09-29 12:07:58 -04:00
|
|
|
|
2021-08-04 16:08:51 -04:00
|
|
|
public function test_profile_has_search_links_in_created_entity_lists()
|
|
|
|
{
|
|
|
|
$user = $this->getEditor();
|
2021-09-13 17:54:21 -04:00
|
|
|
$resp = $this->actingAs($this->getAdmin())->get('/user/' . $user->slug);
|
2021-08-04 16:08:51 -04:00
|
|
|
|
|
|
|
$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) {
|
2021-09-13 17:54:21 -04:00
|
|
|
$resp->assertElementContains('[href$="' . $link . '"]', 'View All');
|
2021-08-04 16:08:51 -04:00
|
|
|
}
|
|
|
|
}
|
2016-02-18 14:32:07 -05:00
|
|
|
}
|