Added unit tests

This commit is contained in:
Henry Whitaker
2020-07-24 11:46:08 +01:00
parent 6db835233c
commit 7640f22db8
5 changed files with 162 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class AppVersionTest extends TestCase
{
/**
* Test the version CLI command
*
* @return void
*/
public function testVersionCommand()
{
$response = $this->artisan('speedtest:version')
->expectsOutput('Speedtest Tracker v' . config('speedtest.version'));
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class ConfigTest extends TestCase
{
use RefreshDatabase;
private $configStructure = [
'base',
'graphs' => [
'download_upload_graph_enabled' => [],
'download_upload_graph_width' => [],
'ping_graph_enabled' => [],
'ping_graph_width' => [],
'failure_graph_enabled' => [],
'failure_graph_width' => [],
],
'editable' => [
'slack_webhook',
'telegram_bot_token',
'telegram_chat_id'
],
];
/**
* Test config returned by API
*
* @return void
*/
public function testAPIConfig()
{
$response = $this->get('api/settings/config');
$response->assertJsonStructure($this->configStructure);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Tests\Feature;
use App\Rules\Cron;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class CronRuleTest extends TestCase
{
/**
* Test a valid CRON expression
*
* @return void
*/
public function testValidCronValidationRule()
{
$rule = [
'test' => new Cron,
];
$data = [
'test' => '*/5 * * * *',
];
$validator = $this->app['validator']->make($data, $rule);
$this->assertTrue($validator->passes());
}
/**
* Test an invalid CRON expression
*
* @return void
*/
public function testInvalidCronValidationRule()
{
$rule = [
'test' => new Cron,
];
$data = [
'test' => 'invalid',
];
$validator = $this->app['validator']->make($data, $rule);
$this->assertFalse($validator->passes());
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Tests\Feature;
use App\Helpers\SettingsHelper;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class SetSlackWebhookTest extends TestCase
{
use RefreshDatabase;
/**
* Test settings slack webhook via API
*
* @return void
*/
public function testSetSlackWebhookAPI()
{
$response = $this->json('PUT', 'api/settings', [
'name' => 'slack_webhook',
'value' => 'PHPUnitAPI'
]);
$response->assertStatus(200);
$this->assertEquals('PHPUnitAPI', SettingsHelper::get('slack_webhook')->value);
}
}

View File

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