Skip to content

Commit

Permalink
Merge pull request #22 from Newman101/IncreaseCoverage
Browse files Browse the repository at this point in the history
Increase Test Coverage
  • Loading branch information
jremes-foss committed Dec 3, 2019
2 parents a6435b2 + 7dff395 commit 7a5c786
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 9 deletions.
8 changes: 0 additions & 8 deletions app/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,4 @@ public function attachments() {
public function categories() {
return $this->hasOne('App\Category');
}

public function scopeCategoryFilter($q) {
if(request('category')) {
$q->where('category', '=', request('category'));
}

return $q;
}
}
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
//
Commands\CreateAdministrator::class,
];

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/AdminConsoleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Artisan;

class AdminConsoleTest extends TestCase
{
public function testAdminConsoleCommandExists()
{
$this->assertTrue(class_exists(\App\Console\Commands\CreateAdministrator::class));
}

public function testRunAdminConsoleCommandNoInteraction()
{
$cmd = Artisan::call('user:create-admin', ['--no-interaction' => true]);
$this->assertEquals(0, $cmd);
}
}
34 changes: 34 additions & 0 deletions tests/Unit/AttachmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Attachment;
use App\Challenge;

class AttachmentTest extends TestCase
{
use RefreshDatabase;

public function testAttachmentRelationship()
{
$attachment = factory(Attachment::class)->make([
'challenge_id' => 1,
'filename' => 'test.zip',
'url' => 'http://127.0.0.1'
]);

factory(\App\Challenge::class)->create([
'category' => 'Crypto',
'score' => '250',
'title' => 'TEST',
'flag' => 'FLAG{th1s_1s_4_t3stSt}',
'content' => 'This is a test.'
]);

$challenge = $attachment->challenge;
$this->assertEquals('TEST', $challenge->title);
}
}
20 changes: 20 additions & 0 deletions tests/Unit/CategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ public function testChallengesRelationship()
$this->assertEquals('Crypto', $category);
}

public function testHasMany()
{
factory(\App\Challenge::class)->create([
'category' => 'Crypto',
'score' => '250',
'title' => 'TEST',
'flag' => 'FLAG{th1s_1s_4_t3stSt}',
'content' => 'This is a test.'
]);

factory(\App\Category::class)->create([
'category' => 'Test Category',
'description' => 'This is a test category'
]);

$category = new Category();
$challenges = $category->challenges();
$this->assertEquals('object', gettype($challenges));
}

public function testIndex()
{
$response = $this->get('admin/categories');
Expand Down

0 comments on commit 7a5c786

Please sign in to comment.