-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Newman101/BugFixCategories
Bug Fixes
- Loading branch information
Showing
15 changed files
with
225 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ChallengeCategory extends Model | ||
{ | ||
protected $table = "challenge_category"; | ||
|
||
protected $fillable = [ | ||
'category_id', | ||
'challenge_id' | ||
]; | ||
|
||
public function challenges() | ||
{ | ||
return $this->belongsTo('App\Challenge', 'challenge_id', 'id'); | ||
} | ||
|
||
public function categories() | ||
{ | ||
return $this->belongsTo('App\Category', 'category_id', 'id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
/** @var \Illuminate\Database\Eloquent\Factory $factory */ | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(App\ChallengeCategory::class, function (Faker $faker) { | ||
return [ | ||
'category_id' => 1, | ||
'challenge_id' => 1 | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
database/migrations/2020_01_30_195725_create_challenge_category.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateChallengeCategory extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('challenge_category', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->integer('challenge_id')->unsigned(); | ||
$table->integer('category_id')->unsigned(); | ||
$table->foreign('challenge_id')->references('id')->on('challenges'); | ||
$table->foreign('category_id')->references('id')->on('categories'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('challenge_category'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use App\Category; | ||
use App\Challenge; | ||
use App\ChallengeCategory; | ||
|
||
class ChallengeCategoryTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testChallengeCategoryRelationship() | ||
{ | ||
$challenge = factory(Challenge::class)->create([ | ||
'score' => '250', | ||
'title' => 'TEST', | ||
'flag' => 'FLAG{th1s_1s_4_t3st}', | ||
'content' => 'This is a test.' | ||
]); | ||
|
||
$category = factory(Category::class)->create([ | ||
'category' => 'Crypto' | ||
]); | ||
|
||
$challenge_category = factory(ChallengeCategory::class)->create([ | ||
'category_id' => 1, | ||
'challenge_id' => 1 | ||
]); | ||
|
||
$challenge = Challenge::find(1); | ||
$challenge_category = ChallengeCategory::find(1); | ||
|
||
$this->assertEquals(1, $challenge->challenge_categories->challenge_id); | ||
$this->assertEquals(1, $challenge->challenge_categories->category_id); | ||
|
||
// Test categories relationship | ||
$this->assertEquals('Crypto', $challenge->challenge_categories->categories->category); | ||
|
||
// Test challenges relationship | ||
$this->assertEquals(250, $challenge_category->challenges->score); | ||
$this->assertEquals('TEST', $challenge_category->challenges->title); | ||
$this->assertEquals('FLAG{th1s_1s_4_t3st}', $challenge_category->challenges->flag); | ||
$this->assertEquals('This is a test.', $challenge_category->challenges->content); | ||
|
||
} | ||
} |
Oops, something went wrong.