snipe-it/tests/unit/ConsumableTest.php

51 lines
1.8 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
namespace Tests\Unit;
2016-03-25 01:18:05 -07:00
use App\Models\Consumable;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Tests\Unit\BaseTest;
2016-03-25 01:18:05 -07:00
class ConsumableTest extends BaseTest
2016-03-25 01:18:05 -07:00
{
/**
* @var \UnitTester
*/
protected $tester;
public function testFailsEmptyValidation()
{
// An Consumable requires a name, a qty, and a category_id.
$a = Consumable::create();
$this->assertFalse($a->isValid());
2016-03-25 01:18:05 -07:00
$fields = [
'name' => 'name',
'qty' => 'qty',
'category_id' => 'category id',
];
$errors = $a->getErrors();
foreach ($fields as $field => $fieldTitle) {
$this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
}
}
public function testAConsumableHasRelationships()
{
2021-06-10 13:17:44 -07:00
$consumable = Consumable::factory()->cardstock()->create([
'category_id' => $this->createValidCategory('consumable-paper-category')->id,
'manufacturer_id' => $this->createValidManufacturer('apple')->id,
'company_id' => $this->createValidCompany()->id,
'location_id' => $this->createValidLocation()->id,
'user_id' => $this->signIn()->id,
]);
$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
}