snipe-it/tests/unit/SnipeModelTest.php
Daniel Meltzer 5d4920c741 [WIP] Improvements to unit tests. (#3574)
* Improvemenets to unit tests.

* Break up modelfactory into multiple files, populate many states.
* Begin testing validation at the unit test level, test relationships.
* Add tests for Asset::availableForCheckout.
* Model factories now generate all needed relationships on demand,
  which allows us to unit test with a empty database.
* To faciliate the empty database, we move to using sqlite in memory as
  the unit testing database.

* Fix bug with logs of checkouts to non users.

* Fix location finding for assets.  Also Fix location show page to show users associated with location.  Still need some work to show assets.

* More test and generator improvements

* More unit test fixes. PermissionsTest is borked still.

* More Updates

* Rewrite permissionstest.  Check that we have access on the model level rather than via web requests.  Also test delete permissions.

* Fix seeders.

* Make the default asset model factory generate assets that are rtd for testing.

* Save progress.

* Rebase tests, fix department unit test, update database for functional tests.

* Update functional and api tests to use new modelfactory signatures.
2017-06-12 17:39:03 -07:00

103 lines
2.4 KiB
PHP

<?php
use App\Models\SnipeModel;
class SnipeModelTest extends \Codeception\TestCase\Test
{
/**
* @var \UnitTester
*/
protected $tester;
// tests
/**
* @test
*/
protected function _before()
{
Artisan::call('migrate');
}
public function it_sets_purchase_dates_appropriately()
{
$c = new SnipeModel;
$c->purchase_date = '';
$this->assertTrue($c->purchase_date === null);
$c->purchase_date = '2016-03-25 12:35:50';
$this->assertTrue($c->purchase_date==='2016-03-25 12:35:50');
}
/**
* @test
*/
public function it_sets_purchase_costs_appropriately()
{
$c = new SnipeModel;
$c->purchase_cost = '0.00';
$this->assertTrue($c->purchase_cost === null);
$c->purchase_cost = '9.54';
$this->assertTrue($c->purchase_cost===9.54);
$c->purchase_cost = '9.50';
$this->assertTrue($c->purchase_cost===9.5);
}
/**
* @test
*/
public function it_nulls_blank_location_ids_but_not_others()
{
$c = new SnipeModel;
$c->location_id = '';
$this->assertTrue($c->location_id === null);
$c->location_id = '5';
$this->assertTrue($c->location_id==5);
}
/**
* @test
*/
public function it_nulls_blank_categories_but_not_others()
{
$c = new SnipeModel;
$c->category_id = '';
$this->assertTrue($c->category_id === null);
$c->category_id = '1';
$this->assertTrue($c->category_id==1);
}
/**
* @test
*/
public function it_nulls_blank_suppliers_but_not_others()
{
$c = new SnipeModel;
$c->supplier_id = '';
$this->assertTrue($c->supplier_id === null);
$c->supplier_id = '4';
$this->assertTrue($c->supplier_id==4);
}
/**
* @test
*/
public function it_nulls_blank_depreciations_but_not_others()
{
$c = new SnipeModel;
$c->depreciation_id = '';
$this->assertTrue($c->depreciation_id === null);
$c->depreciation_id = '4';
$this->assertTrue($c->depreciation_id==4);
}
/**
* @test
*/
public function it_nulls_blank_manufacturers_but_not_others()
{
$c = new SnipeModel;
$c->manufacturer_id = '';
$this->assertTrue($c->manufacturer_id === null);
$c->manufacturer_id = '4';
$this->assertTrue($c->manufacturer_id==4);
}
}