2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
use App\Models\Consumable;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
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
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
public function testConsumableAdd()
|
|
|
|
{
|
2017-06-12 17:39:03 -07:00
|
|
|
$consumable = factory(Consumable::class)->make();
|
2016-03-25 01:18:05 -07:00
|
|
|
$values = [
|
|
|
|
'name' => $consumable->name,
|
|
|
|
'qty' => $consumable->qty,
|
|
|
|
'category_id' => $consumable->category_id,
|
|
|
|
'company_id' => $consumable->company_id,
|
|
|
|
];
|
|
|
|
|
|
|
|
Consumable::create($values);
|
|
|
|
$this->tester->seeRecord('consumables', $values);
|
|
|
|
}
|
|
|
|
|
2017-06-12 17:39:03 -07:00
|
|
|
public function testFailsEmptyValidation()
|
|
|
|
{
|
|
|
|
// An Consumable requires a name, a qty, and a category_id.
|
|
|
|
$a = Consumable::create();
|
|
|
|
$this->assertFalse($a->isValid());
|
|
|
|
|
|
|
|
$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()
|
|
|
|
{
|
|
|
|
$consumable = factory(Consumable::class)->create();
|
|
|
|
$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
|
|
|
}
|