Ejemplo n.º 1
0
 public function test_restoreTopicToSection_restores_a_topic_and_views()
 {
     // GIVEN I have a topic with posts in a section
     $section = factory(Section::class, 1)->create();
     $topic = factory(Topic::class, 1)->create(['section_id' => $section->id]);
     factory(Post::class, 20)->create(['topic_id' => $topic->id]);
     $topic_id = $topic->id;
     // and a user reads that topic
     $user = factory(User::class, 1)->create();
     \Nexus\Helpers\ViewHelper::updateReadProgress($user, $topic);
     $viewsCount = $topic->views->count();
     $this->assertNotEquals($viewsCount, 0);
     // and then that topic is deleted
     $topic->delete();
     // check topic deleted
     $this->assertTrue($topic->trashed());
     // and that we have no views - need to use trashed here
     $this->assertEquals(Topic::withTrashed()->find($topic_id)->views->count(), 0);
     // WHEN the topic is restored to the section
     \Nexus\Helpers\RestoreHelper::restoreTopicToSection($topic, $section);
     // check posts and views are restored
     $this->assertEquals($topic->views->count(), $viewsCount);
     // THEN the topic is restored
     $this->assertFalse($topic->trashed());
 }
Ejemplo n.º 2
0
 public function test_getTopicStatus_does_not_indicate_never_read_for_a_viewed_topic()
 {
     $faker = \Faker\Factory::create();
     // GIVEN we have a user
     $user = factory(User::class, 1)->create();
     // AND we add a topic
     $topic = factory(Topic::class, 1)->create();
     // WHEN the user has read the topic
     \Nexus\Helpers\ViewHelper::updateReadProgress($user, $topic);
     // THEN the topic does not appear new to the user
     $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus($user, $topic);
     $this->assertFalse($topicStatus['never_read']);
 }
Ejemplo n.º 3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($topic_id)
 {
     $posts = \Nexus\Post::with('author')->where('topic_id', $topic_id)->orderBy('id', 'dsc');
     $topic = \Nexus\Topic::findOrFail($topic_id);
     // is this topic readonly to the authenticated user?
     $readonly = true;
     if ($topic->readonly == false) {
         $readonly = false;
     }
     if ($topic->section->moderator->id === \Auth::user()->id) {
         $readonly = false;
     }
     if (\Auth::user()->administrator) {
         $readonly = false;
     }
     // is this topic secret to the authenticated user?
     $userCanSeeSecrets = false;
     if ($topic->section->moderator->id === \Auth::user()->id) {
         $userCanSeeSecrets = true;
     }
     if (\Auth::user()->administrator) {
         $userCanSeeSecrets = true;
     }
     // get the previously read progress so we can indicate this in the view
     $readProgress = \Nexus\Helpers\ViewHelper::getReadProgress(\Auth::user(), $topic);
     // get the subscription status
     $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus(\Auth::user(), $topic);
     $unsubscribed = $topicStatus['unsubscribed'];
     \Nexus\Helpers\ViewHelper::updateReadProgress(\Auth::user(), $topic);
     \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Reading <em>{$topic->title}</em>", action('Nexus\\TopicController@show', ['id' => $topic->id]));
     $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcrumbForTopic($topic);
     return view('topics.index', compact('topic', 'posts', 'readonly', 'userCanSeeSecrets', 'readProgress', 'breadcrumbs', 'unsubscribed'));
 }