2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
2021-11-30 20:09:29 -08:00
|
|
|
namespace Tests\Unit;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
use App\Models\Consumable;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2021-06-10 13:15:52 -07:00
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2021-11-30 20:09:29 -08:00
|
|
|
use Tests\Unit\BaseTest;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-07-11 20:37:02 -07:00
|
|
|
class ConsumableTest extends BaseTest
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \UnitTester
|
|
|
|
*/
|
|
|
|
protected $tester;
|
2017-06-12 17:39:03 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function testFailsEmptyValidation()
|
|
|
|
{
|
2018-07-23 06:48:21 -07:00
|
|
|
// An Consumable requires a name, a qty, and a category_id.
|
2021-06-10 13:15:52 -07:00
|
|
|
$a = Consumable::create();
|
|
|
|
$this->assertFalse($a->isValid());
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$fields = [
|
2018-07-23 06:48:21 -07:00
|
|
|
'name' => 'name',
|
|
|
|
'qty' => 'qty',
|
2021-06-10 13:15:52 -07:00
|
|
|
'category_id' => 'category id',
|
2018-07-23 06:48:21 -07:00
|
|
|
];
|
2021-06-10 13:15:52 -07:00
|
|
|
$errors = $a->getErrors();
|
|
|
|
foreach ($fields as $field => $fieldTitle) {
|
|
|
|
$this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
|
|
|
|
}
|
|
|
|
}
|
2017-06-12 17:39:03 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function testAConsumableHasRelationships()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$consumable = Consumable::factory()->cardstock()->create([
|
2018-07-23 06:48:21 -07:00
|
|
|
'category_id' => $this->createValidCategory('consumable-paper-category')->id,
|
|
|
|
'manufacturer_id' => $this->createValidManufacturer('apple')->id,
|
|
|
|
'company_id' => $this->createValidCompany()->id,
|
|
|
|
'location_id' => $this->createValidLocation()->id,
|
2021-06-10 13:15:52 -07:00
|
|
|
'user_id' => $this->signIn()->id,
|
2018-07-23 06:48:21 -07:00
|
|
|
]);
|
2017-06-12 17:39:03 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$this->assertInstanceOf(App\Models\User::class, $consumable->admin);
|
|
|
|
$this->assertInstanceOf(App\Models\Company::class, $consumable->company);
|
|
|
|
$this->assertInstanceOf(App\Models\Manufacturer::class, $consumable->manufacturer);
|
|
|
|
$this->assertInstanceOf(App\Models\Location::class, $consumable->location);
|
|
|
|
$this->assertInstanceOf(App\Models\Category::class, $consumable->category);
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|