initial commit
This commit is contained in:
commit
1e1aa7d461
215 changed files with 35140 additions and 0 deletions
52
tests/Feature/Models/CharacterTest.php
Normal file
52
tests/Feature/Models/CharacterTest.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\CharacterProfession;
|
||||
use App\Models\Character;
|
||||
|
||||
class CharacterTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Test user relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_user_relationship()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$character = Character::factory()
|
||||
->for($user)
|
||||
->create();
|
||||
|
||||
$this->assertEquals($user->id, $character->user->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test character profession relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_profession_relationship()
|
||||
{
|
||||
$this->seed(\Database\Seeders\SettingsSeeders\ProfessionsTableSeeder::class);
|
||||
|
||||
$professions = CharacterProfession::factory(2)->create();
|
||||
$character = Character::factory()->create();
|
||||
|
||||
$character->professions()->save($professions[0]);
|
||||
$character->professions()->save($professions[1]);
|
||||
|
||||
$this->assertEquals(2, $character->professions->count());
|
||||
|
||||
foreach($professions as $profession) {
|
||||
$this->assertContains($profession->id, $character->professions->pluck('id')->toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
55
tests/Feature/Models/ItemTest.php
Normal file
55
tests/Feature/Models/ItemTest.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\Recipe;
|
||||
use App\Models\Item;
|
||||
|
||||
class ItemTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Test recipe relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_recipe_relationship()
|
||||
{
|
||||
$item = Item::factory()->create();
|
||||
$recipe = Recipe::factory()
|
||||
->for($item, 'craft')
|
||||
->create();
|
||||
|
||||
$this->assertEquals($recipe->id, $item->recipe->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test quantity attribute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_quantity_attribute()
|
||||
{
|
||||
$recipe = Recipe::factory()->create();
|
||||
$item = Item::factory()->create();
|
||||
$recipe->reagents()->attach($item, ['quantity' => 5]);
|
||||
|
||||
$this->assertEquals(5, $recipe->reagents[0]->quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test quantity attribute missing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_quantity_attribute_missing()
|
||||
{
|
||||
$item = Item::factory()->create();
|
||||
|
||||
$this->assertNull($item->quantity);
|
||||
}
|
||||
}
|
||||
144
tests/Feature/Models/RecipeTest.php
Normal file
144
tests/Feature/Models/RecipeTest.php
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
use App\Models\Recipe;
|
||||
use App\Models\RecipeCategory;
|
||||
use App\Models\Profession;
|
||||
use App\Models\CharacterProfession;
|
||||
use App\Models\Character;
|
||||
use App\Models\Item;
|
||||
|
||||
class RecipeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Test profession relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_profession_relationship()
|
||||
{
|
||||
$profession = Profession::factory()->create();
|
||||
|
||||
$recipe = Recipe::factory()
|
||||
->for($profession)
|
||||
->create();
|
||||
|
||||
$this->assertEquals($profession->id, $recipe->profession->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test category relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_category_relationship()
|
||||
{
|
||||
$category = RecipeCategory::factory()->create();
|
||||
|
||||
$recipe = Recipe::factory()
|
||||
->for($category, 'category')
|
||||
->create();
|
||||
|
||||
$this->assertEquals($category->id, $recipe->category->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test craft relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_craft_relationship()
|
||||
{
|
||||
$item = Item::factory()->create();
|
||||
|
||||
$recipe = Recipe::factory()
|
||||
->for($item, 'craft')
|
||||
->create();
|
||||
|
||||
$this->assertEquals($item->id, $recipe->craft->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test character profession relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_character_profession_relationship()
|
||||
{
|
||||
$profession = Profession::factory()->create();
|
||||
$ch_profs = CharacterProfession::factory(2)->create([ 'profession_id' => $profession->id ]);
|
||||
$characters = Character::factory(2)->create();
|
||||
|
||||
$characters[0]->professions()->save($ch_profs[0]);
|
||||
$characters[1]->professions()->save($ch_profs[1]);
|
||||
|
||||
$recipe = Recipe::factory()
|
||||
->for($profession)
|
||||
->create();
|
||||
|
||||
$characters[0]->professions[0]->recipes()->save($recipe);
|
||||
$characters[1]->professions[0]->recipes()->save($recipe);
|
||||
|
||||
$professions = $recipe->character_profession;
|
||||
|
||||
$this->assertEquals($ch_profs[0]->id, $professions[0]->id);
|
||||
$this->assertEquals($ch_profs[1]->id, $professions[1]->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test crafters relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_crafters_relationship()
|
||||
{
|
||||
$profession = Profession::factory()->create();
|
||||
$ch_profs = CharacterProfession::factory(2)->create([ 'profession_id' => $profession->id ]);
|
||||
$characters = Character::factory(2)->create();
|
||||
|
||||
$characters[0]->professions()->save($ch_profs[0]);
|
||||
$characters[1]->professions()->save($ch_profs[1]);
|
||||
|
||||
$recipe = Recipe::factory()
|
||||
->for($profession)
|
||||
->create();
|
||||
|
||||
// Make both character learn the recipe.
|
||||
$characters[0]->professions[0]->learn($recipe);
|
||||
$characters[1]->professions[0]->learn($recipe);
|
||||
|
||||
$crafters = $recipe->crafters;
|
||||
|
||||
$this->assertEquals($crafters[0]->id, $characters[0]->id);
|
||||
$this->assertEquals($crafters[1]->id, $characters[1]->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test reagants relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_reagents_relationship()
|
||||
{
|
||||
$profession = Profession::factory()->create();
|
||||
$items = Item::factory(3)->create();
|
||||
|
||||
$recipe = Recipe::factory()
|
||||
->for($profession)
|
||||
->create();
|
||||
|
||||
$recipe->reagents()->attach($items[0], ['quantity' => 1]);
|
||||
$recipe->reagents()->attach($items[1], ['quantity' => 4]);
|
||||
$recipe->reagents()->attach($items[2], ['quantity' => 10]);
|
||||
|
||||
$this->assertEquals($items[0]->id, $recipe->reagents[0]->id);
|
||||
$this->assertEquals($items[1]->id, $recipe->reagents[1]->id);
|
||||
$this->assertEquals($items[2]->id, $recipe->reagents[2]->id);
|
||||
}
|
||||
}
|
||||
Reference in a new issue