mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-24 14:31:52 +01:00
Added unit tests
This commit is contained in:
21
tests/Feature/AppVersionTest.php
Normal file
21
tests/Feature/AppVersionTest.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
41
tests/Feature/ConfigTest.php
Normal file
41
tests/Feature/ConfigTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
49
tests/Feature/CronRuleTest.php
Normal file
49
tests/Feature/CronRuleTest.php
Normal 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());
|
||||
}
|
||||
}
|
||||
29
tests/Feature/SetSlackWebhookTest.php
Normal file
29
tests/Feature/SetSlackWebhookTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
22
tests/Feature/SettingsTest.php
Normal file
22
tests/Feature/SettingsTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user