Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add ForumController tests #1213

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@
Route::get('/subscriptions', 'ForumController@subscriptions')->name('forum_subscriptions');
Route::get('/latest/topics', 'ForumController@latestTopics')->name('forum_latest_topics');
Route::get('/latest/posts', 'ForumController@latestPosts')->name('forum_latest_posts');
Route::get('/search', 'ForumController@search')->name('forum_search');
Route::get('/search', 'ForumController@search')->name('forum_search_form');

Route::group(['prefix' => 'topics'], function () {
Expand Down
199 changes: 199 additions & 0 deletions tests/Feature/Http/Controllers/ForumControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php

namespace Tests\Feature\Http\Controllers;

use App\Models\Forum;
use App\Models\Permission;
use App\Models\User;
use GroupsTableSeeder;
use Tests\TestCase;
use UsersTableSeeder;

/**
* @see \App\Http\Controllers\ForumController
*/
class ForumControllerTest extends TestCase
{
/** @test */
public function index_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

$user = factory(User::class)->create();

$this->actingAs($user)->get(route('forums.index'))
->assertOk()
->assertViewIs('forum.index')
->assertViewHas('categories')
->assertViewHas('num_posts')
->assertViewHas('num_forums')
->assertViewHas('num_topics');
}

/** @test */
public function latest_posts_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

$user = factory(User::class)->create();

$this->actingAs($user)->get(route('forum_latest_posts'))
->assertOk()
->assertViewIs('forum.latest_posts')
->assertViewHas('results')
->assertViewHas('user')
->assertViewHas('num_posts')
->assertViewHas('num_forums')
->assertViewHas('num_topics');
}

/** @test */
public function latest_topics_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

$user = factory(User::class)->create();

$this->actingAs($user)->get(route('forum_latest_topics'))
->assertOk()
->assertViewIs('forum.latest_topics')
->assertViewHas('results')
->assertViewHas('user')
->assertViewHas('num_posts')
->assertViewHas('num_forums')
->assertViewHas('num_topics');
}

/** @test */
public function search_topics_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

$user = factory(User::class)->create();

$this->actingAs($user)->get(route('forum_search_form'))
->assertOk()
->assertViewIs('forum.results_topics')
->assertViewHas('categories')
->assertViewHas('results')
->assertViewHas('user')
->assertViewHas('name')
->assertViewHas('body')
->assertViewHas('num_posts')
->assertViewHas('num_forums')
->assertViewHas('num_topics')
->assertViewHas('params');
}

/** @test */
public function search_posts_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

$user = factory(User::class)->create();

$this->actingAs($user)->call('GET', route('forum_search_form', ['body' => 1]))
->assertOk()
->assertViewIs('forum.results_posts')
->assertViewHas('categories')
->assertViewHas('results')
->assertViewHas('user')
->assertViewHas('name')
->assertViewHas('body')
->assertViewHas('num_posts')
->assertViewHas('num_forums')
->assertViewHas('num_topics')
->assertViewHas('params');
}

/** @test */
public function show_category_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

// This Forum has a parent Forum, which makes it a "Forum Category".

$parentForum = factory(Forum::class)->create();

$permissions = factory(Permission::class)->create([
'forum_id' => $parentForum->id,
'show_forum' => true,
]);

$forum = factory(Forum::class)->create([
'parent_id' => $parentForum->id,
]);

// Note that permissions are not necessary on the parent Forum, and
// the Group ID is instead derived from the child ("Forum Category")
// permissions.

$user = factory(User::class)->create([
'group_id' => $permissions['group_id'],
]);

$this->actingAs($user)->get(route('forums.show', ['id' => $forum->id]))
->assertViewIs('forum.display')
->assertViewHas('forum')
->assertViewHas('topics')
->assertViewHas('category')
->assertViewHas('num_posts')
->assertViewHas('num_forums')
->assertViewHas('num_topics');
}

/** @test */
public function show_forum_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

// This Forum does not have a parent, which makes it a proper Forum
// (and not a "Forum Category").

$forum = factory(Forum::class)->create([
'parent_id' => 0,
]);

$permissions = factory(Permission::class)->create([
'forum_id' => $forum->id,
'show_forum' => true,
]);

$user = factory(User::class)->create([
'group_id' => $permissions['group_id'],
]);

$this->actingAs($user)->get(route('forums.show', ['id' => $forum->id]))
->assertRedirect(route('forums.categories.show', ['id' => $forum->id]));
}

/** @test */
public function subscriptions_returns_an_ok_response()
{
$this->seed(UsersTableSeeder::class);
$this->seed(GroupsTableSeeder::class);

$user = factory(User::class)->create();

$this->actingAs($user)->get(route('forum_subscriptions'))
->assertOk()
->assertViewIs('forum.subscriptions')
->assertViewHas('results')
->assertViewHas('user')
->assertViewHas('name')
->assertViewHas('body')
->assertViewHas('num_posts')
->assertViewHas('num_forums')
->assertViewHas('num_topics')
->assertViewHas('params')
->assertViewHas('forum_neos')
->assertViewHas('topic_neos');
}
}
148 changes: 0 additions & 148 deletions tests/Todo/Feature/Http/Controllers/ForumControllerTest.php

This file was deleted.