test: Add feature tests

This commit is contained in:
Attila Kerekes
2022-12-04 10:14:07 +01:00
committed by Attila Kerekes
parent 52620bc331
commit 45cc84c99c
17 changed files with 360 additions and 31 deletions

50
tests/.env.testing Normal file
View File

@@ -0,0 +1,50 @@
APP_NAME=Heimdall
APP_ENV=local
APP_KEY=
APP_DEBUG=false
APP_URL=http://localhost
LOG_CHANNEL=daily
DB_CONNECTION=sqlite
DB_DATABASE=test.sqlite
#DB_CONNECTION=<mysql | pgsql>
#DB_HOST=<hostname | ip>
#DB_PORT=<port number>
#DB_DATABASE=<database>
#DB_USERNAME=<user>
#DB_PASSWORD=<password>
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

View File

@@ -15,6 +15,8 @@ trait CreatesApplication
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->loadEnvironmentFrom('tests/.env.testing');
$app->make(Kernel::class)->bootstrap();
return $app;

View File

@@ -0,0 +1,83 @@
<?php
namespace Tests\Feature;
use App\Item;
use App\ItemTag;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DashTest extends TestCase
{
use RefreshDatabase;
/**
* Helpers
*/
private function addPinnedItemWithTitleToDB($title)
{
$item = Item::factory()
->create([
'title' => $title,
'pinned' => 1,
]);
ItemTag::factory()->create([
'item_id' => $item->id,
'tag_id' => 0,
]);
}
private function addTagWithTitleToDB($title)
{
Item::factory()
->create([
'title' => $title,
'type' => 1,
]);
}
/**
* Test Cases
*/
public function test_loads_empty_dash()
{
$this->seed();
$response = $this->get('/');
$response->assertStatus(200);
}
public function test_displays_items_on_the_dash()
{
$this->seed();
$this->addPinnedItemWithTitleToDB('Item 1');
$this->addPinnedItemWithTitleToDB('Item 2');
$this->addPinnedItemWithTitleToDB('Item 3');
$response = $this->get('/');
$response->assertStatus(200);
$response->assertSee('Item 1');
$response->assertSee('Item 2');
$response->assertSee('Item 3');
}
public function test_displays_tags_on_the_dash()
{
$this->seed();
$this->addTagWithTitleToDB('Tag 1');
$this->addTagWithTitleToDB('Tag 2');
$response = $this->get('/');
$response->assertStatus(200);
$response->assertSee('Tag 1');
$response->assertSee('Tag 2');
}
}

View File

@@ -1,23 +0,0 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
/**
* A basic test example.
*
* @return void
*/
public function test_app_loads()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ItemCreateTest extends TestCase
{
use RefreshDatabase;
public function test_displays_the_item_create_page()
{
$this->seed();
$response = $this->get('/items/create');
$response->assertStatus(200);
}
/**
* @return void
*/
public function test_display_the_home_dashboard_tag()
{
$this->seed();
$response = $this->get('/items/create');
$response->assertSee('Home dashboard');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Tests\Feature;
use App\Item;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ItemListTest extends TestCase
{
use RefreshDatabase;
protected function addItemWithTitleToDB($title)
{
Item::factory()
->create([
'title' => $title
]);
}
public function test_displays_items_on_the_item_list_page()
{
$this->addItemWithTitleToDB('Item 1');
$this->addItemWithTitleToDB('Item 2');
$this->addItemWithTitleToDB('Item 3');
$response = $this->get('/items');
$response->assertStatus(200);
$response->assertSee('Item 1');
$response->assertSee('Item 2');
$response->assertSee('Item 3');
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class SettingsTest extends TestCase
{
use RefreshDatabase;
public function test_displays_the_settings_page()
{
$this->seed();
$response = $this->get('/settings');
$response->assertStatus(200);
$response->assertSeeInOrder([
'Version',
'Language',
'Support',
'Donate',
'Background Image',
'Homepage Search',
'Default Search Provider',
'Link opens in',
'Custom CSS',
'Custom JavaScript',
]);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Tests\Feature;
use App\Item;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class TagListTest extends TestCase
{
use RefreshDatabase;
private function addTagWithTitleToDB($title)
{
Item::factory()
->create([
'title' => $title,
'type' => 1,
]);
}
public function test_displays_the_tags_on_the_tag_list_page()
{
$this->addTagWithTitleToDB('Tag 1');
$this->addTagWithTitleToDB('Tag 2');
$this->addTagWithTitleToDB('Tag 3');
$response = $this->get('/tags');
$response->assertStatus(200);
$response->assertSee('Tag 1');
$response->assertSee('Tag 2');
$response->assertSee('Tag 3');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Tests\Feature;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UserListTest extends TestCase
{
use RefreshDatabase;
protected function addUserWithNameToDB($name)
{
User::factory()
->create([
'username' => $name
]);
}
public function test_displays_admin_on_user_list_page_when_default_install()
{
$this->seed();
$response = $this->get('/users');
$response->assertStatus(200);
$response->assertSee('admin');
}
public function test_displays_users_on_user_list_page()
{
$this->seed();
$this->addUserWithNameToDB('User 1');
$response = $this->get('/users');
$response->assertStatus(200);
$response->assertSee('User 1');
}
}