Dan Brown

Added tests for profile pages

...@@ -29,18 +29,19 @@ class ActivityService ...@@ -29,18 +29,19 @@ class ActivityService
29 */ 29 */
30 public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false) 30 public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false)
31 { 31 {
32 - $this->activity->user_id = $this->user->id; 32 + $activity = $this->activity->newInstance();
33 - $this->activity->book_id = $bookId; 33 + $activity->user_id = $this->user->id;
34 - $this->activity->key = strtolower($activityKey); 34 + $activity->book_id = $bookId;
35 + $activity->key = strtolower($activityKey);
35 if ($extra !== false) { 36 if ($extra !== false) {
36 - $this->activity->extra = $extra; 37 + $activity->extra = $extra;
37 } 38 }
38 - $entity->activity()->save($this->activity); 39 + $entity->activity()->save($activity);
39 $this->setNotification($activityKey); 40 $this->setNotification($activityKey);
40 } 41 }
41 42
42 /** 43 /**
43 - * Adds a activity history with a message & without binding to a entitiy. 44 + * Adds a activity history with a message & without binding to a entity.
44 * @param $activityKey 45 * @param $activityKey
45 * @param int $bookId 46 * @param int $bookId
46 * @param bool|false $extra 47 * @param bool|false $extra
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 @include('partials/entity-list', ['entities' => $recents]) 14 @include('partials/entity-list', ['entities' => $recents])
15 </div> 15 </div>
16 16
17 - <div class="col-md-4 col-md-offset-1"> 17 + <div class="col-md-4 col-md-offset-1" id="recent-activity">
18 <div class="margin-top large">&nbsp;</div> 18 <div class="margin-top large">&nbsp;</div>
19 <h3>Recent Activity</h3> 19 <h3>Recent Activity</h3>
20 @include('partials/activity-list', ['activity' => $activity]) 20 @include('partials/activity-list', ['activity' => $activity])
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
22 </div> 22 </div>
23 </div> 23 </div>
24 </div> 24 </div>
25 - <div class="col-md-5 text-bigger"> 25 + <div class="col-md-5 text-bigger" id="content-counts">
26 <div class="text-muted">Created Content</div> 26 <div class="text-muted">Created Content</div>
27 <div class="text-book"> 27 <div class="text-book">
28 <i class="zmdi zmdi-book zmdi-hc-fw"></i> {{ $assetCounts['books'] }} {{ str_plural('Book', $assetCounts['books']) }} 28 <i class="zmdi zmdi-book zmdi-hc-fw"></i> {{ $assetCounts['books'] }} {{ str_plural('Book', $assetCounts['books']) }}
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
65 @endif 65 @endif
66 </div> 66 </div>
67 67
68 - <div class="col-sm-4 col-sm-offset-1"> 68 + <div class="col-sm-4 col-sm-offset-1" id="recent-activity">
69 <h3>Recent Activity</h3> 69 <h3>Recent Activity</h3>
70 @include('partials/activity-list', ['activity' => $activity]) 70 @include('partials/activity-list', ['activity' => $activity])
71 </div> 71 </div>
......
File mode changed
...@@ -109,4 +109,18 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase ...@@ -109,4 +109,18 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
109 109
110 return $this; 110 return $this;
111 } 111 }
112 +
113 + /**
114 + * Click the text within the selected element.
115 + * @param $parentElement
116 + * @param $linkText
117 + * @return $this
118 + */
119 + protected function clickInElement($parentElement, $linkText)
120 + {
121 + $elem = $this->crawler->filter($parentElement);
122 + $link = $elem->selectLink($linkText);
123 + $this->visit($link->link()->getUri());
124 + return $this;
125 + }
112 } 126 }
......
1 +<?php
2 +
3 +class UserProfileTest extends TestCase
4 +{
5 + protected $user;
6 +
7 + public function setUp()
8 + {
9 + parent::setUp();
10 + $this->user = \BookStack\User::all()->last();
11 + }
12 +
13 + public function test_profile_page_shows_name()
14 + {
15 + $this->asAdmin()
16 + ->visit('/user/' . $this->user->id)
17 + ->see($this->user->name);
18 + }
19 +
20 + public function test_profile_page_shows_recent_entities()
21 + {
22 + $content = $this->createEntityChainBelongingToUser($this->user, $this->user);
23 +
24 + $this->asAdmin()
25 + ->visit('/user/' . $this->user->id)
26 + // Check the recently created page is shown
27 + ->see($content['page']->name)
28 + // Check the recently created chapter is shown
29 + ->see($content['chapter']->name)
30 + // Check the recently created book is shown
31 + ->see($content['book']->name);
32 + }
33 +
34 + public function test_profile_page_shows_created_content_counts()
35 + {
36 + $newUser = $this->getNewUser();
37 +
38 + $this->asAdmin()->visit('/user/' . $newUser->id)
39 + ->see($newUser->name)
40 + ->seeInElement('#content-counts', '0 Books')
41 + ->seeInElement('#content-counts', '0 Chapters')
42 + ->seeInElement('#content-counts', '0 Pages');
43 +
44 + $this->createEntityChainBelongingToUser($newUser, $newUser);
45 +
46 + $this->asAdmin()->visit('/user/' . $newUser->id)
47 + ->see($newUser->name)
48 + ->seeInElement('#content-counts', '1 Book')
49 + ->seeInElement('#content-counts', '1 Chapter')
50 + ->seeInElement('#content-counts', '1 Page');
51 + }
52 +
53 + public function test_profile_page_shows_recent_activity()
54 + {
55 + $newUser = $this->getNewUser();
56 + $this->actingAs($newUser);
57 + $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
58 + Activity::add($entities['book'], 'book_update', $entities['book']->id);
59 + Activity::add($entities['page'], 'page_create', $entities['book']->id);
60 +
61 + $this->asAdmin()->visit('/user/' . $newUser->id)
62 + ->seeInElement('#recent-activity', 'updated book')
63 + ->seeInElement('#recent-activity', 'created page')
64 + ->seeInElement('#recent-activity', $entities['page']->name);
65 + }
66 +
67 + public function test_clicking_user_name_in_activity_leads_to_profile_page()
68 + {
69 + $newUser = $this->getNewUser();
70 + $this->actingAs($newUser);
71 + $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
72 + Activity::add($entities['book'], 'book_update', $entities['book']->id);
73 + Activity::add($entities['page'], 'page_create', $entities['book']->id);
74 +
75 + $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
76 + ->seePageIs('/user/' . $newUser->id)
77 + ->see($newUser->name);
78 + }
79 +
80 +}