コード例 #1
0
 public function test_getTopicStatus_returns_subscribed_when_a_user_resubscribes()
 {
     $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 is unsubscribed from the topic
     \Nexus\Helpers\ViewHelper::unsubscribeFromTopic($user, $topic);
     // THEN the topic does not appear new to the user
     $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus($user, $topic);
     $this->assertTrue($topicStatus['unsubscribed']);
     // WHEN the user is unsubscribed from the topic
     \Nexus\Helpers\ViewHelper::subscribeToTopic($user, $topic);
     // THEN the topic does not appear new to the user
     $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus($user, $topic);
     $this->assertFalse($topicStatus['unsubscribed']);
 }
コード例 #2
0
 /**
  *
  * toggles a users subscription to the topic
  */
 public function updateSubscription(Requests\Topic\SubscriptionRequest $request, $id)
 {
     $input = $request->all();
     $topic = \Nexus\Topic::findOrFail($id);
     if ($input['command'] === 'subscribe') {
         \Nexus\Helpers\ViewHelper::subscribeToTopic(\Auth::user(), $topic);
         $message = '**Subscribed!** _Catch-up_ will return you here when new comments are added.';
     } else {
         \Nexus\Helpers\ViewHelper::unsubscribeFromTopic(\Auth::user(), $topic);
         $message = '**Unsubscribed!** New comments here will be hidden from _Catch-up_.';
     }
     \Nexus\Helpers\FlashHelper::showAlert($message, 'success');
     return redirect()->route('topic.show', ['id' => $topic->id]);
 }