[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.
This commit is contained in:
Daniel Meltzer 2017-06-12 19:39:03 -05:00 committed by snipe
parent 966a736602
commit 5d4920c741
64 changed files with 1550 additions and 733 deletions

View file

@ -1,7 +1,8 @@
APP_ENV=local APP_ENV=testing
APP_DEBUG=true APP_DEBUG=true
APP_URL=http://snipe-it.localapp APP_URL=http://snipe-it.localapp
DB_CONNECTION=mysql DB_CONNECTION=sqlite_testing
DB_DEFAULT=sqlite_testing
DB_HOST=localhost DB_HOST=localhost
DB_DATABASE=snipeittests DB_DATABASE=snipeittests
DB_USERNAME=snipeit DB_USERNAME=snipeit

View file

@ -50,7 +50,11 @@ class UsersController extends Controller
} }
if ($request->has('company_id')) { if ($request->has('company_id')) {
$users = $users->where('company_id','=',$request->input('company_id')); $users = $users->where('company_id', '=', $request->input('company_id'));
}
if ($request->has('location_id')) {
$users = $users->where('location_id', '=', $request->input('location_id'));
} }
if ($request->has('department_id')) { if ($request->has('department_id')) {

View file

@ -139,6 +139,7 @@ class Asset extends Depreciable
* @param null $name * @param null $name
* @return bool * @return bool
*/ */
//FIXME: The admin parameter is never used. Can probably be removed.
public function checkOut($target, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null) public function checkOut($target, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null)
{ {
if (!$target) { if (!$target) {
@ -163,7 +164,7 @@ class Asset extends Depreciable
} }
if ($this->save()) { if ($this->save()) {
$log = $this->logCheckout($note); $this->logCheckout($note, $target);
// if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) { // if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
// $this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note); // $this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note);
// } // }
@ -272,15 +273,13 @@ class Asset extends Depreciable
**/ **/
public function assetLoc() public function assetLoc()
{ {
if ($this->assignedTo) {
return $this->assignedTo->userloc();
}
if (!empty($this->assignedType())) { if (!empty($this->assignedType())) {
if ($this->assignedType() == self::ASSET) { if ($this->assignedType() == self::ASSET) {
return $this->assignedTo->assetloc(); // Recurse until we have a final location return $this->assignedTo->assetloc(); // Recurse until we have a final location
} elseif ($this->assignedType() == self::LOCATION) { } elseif ($this->assignedType() == self::LOCATION) {
return $this->assignedTo(); return $this->assignedTo();
} elseif ($this->assignedType() == self::USER) {
return $this->assignedTo->userLoc();
} }
} }
return $this->defaultLoc(); return $this->defaultLoc();

View file

@ -45,12 +45,17 @@ trait Loggable
$log->user_id = Auth::user()->id; $log->user_id = Auth::user()->id;
// @FIXME This needs to be generalized with new asset checkout. // @FIXME This needs to be generalized with new asset checkout.
if (!is_null($this->asset_id) || isset($target)) { if(isset($target)) {
$log->target_type = Asset::class; $log->target_type = get_class($target);
$log->target_id = $this->asset_id; $log->target_id = $target->id;
} elseif (!is_null($this->assigned_to)) { } else {
$log->target_type = User::class; if (!is_null($this->asset_id)) {
$log->target_id = $this->assigned_to; $log->target_type = Asset::class;
$log->target_id = $this->asset_id;
} elseif (!is_null($this->assigned_to)) {
$log->target_type = User::class;
$log->target_id = $this->assigned_to;
}
} }
$item = call_user_func(array($log->target_type, 'find'), $log->target_id); $item = call_user_func(array($log->target_type, 'find'), $log->target_id);

View file

@ -54,7 +54,7 @@ return [
'sqlite_testing' => [ 'sqlite_testing' => [
'driver' => 'sqlite', 'driver' => 'sqlite',
'database' => database_path('testing.sqlite'), 'database' => ':memory:',
'prefix' => '', 'prefix' => '',
], ],

View file

@ -0,0 +1,111 @@
<?php
use App\Models\Actionlog;
$factory->defineAs(App\Models\Actionlog::class, 'asset-upload', function ($faker) {
$asset = factory(App\Models\Asset::class)->create();
return [
'item_type' => get_class($asset),
'item_id' => $asset->id,
'user_id' => function () {
return factory(App\Models\User::class)->create()->id;
},
'filename' => $faker->word,
'action_type' => 'uploaded'
];
});
$factory->defineAs(Actionlog::class, 'asset-checkout', function (Faker\Generator $faker) {
$company = factory(App\Models\Company::class)->create();
$user = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$target = factory(App\Models\User::class)->create(['company_id' => $company->id]);
// $item = factory(App\Models\Asset::class)->create(['company_id' => $company->id]);
return [
'user_id' => $user->id,
'action_type' => 'checkout',
'item_id' => factory(App\Models\Asset::class)->create(['company_id' => $company->id])->id,
'item_type' => App\Models\Asset::class,
'target_id' => $target->id,
'target_type' => get_class($target),
'created_at' => $faker->dateTime(),
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(Actionlog::class, 'license-checkout-asset', function (Faker\Generator $faker) {
$company = factory(App\Models\Company::class)->create();
$user = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$target = factory(App\Models\Asset::class)->create(['company_id' => $company->id]);
$item = factory(App\Models\License::class)->create(['company_id' => $company->id]);
return [
'user_id' => $user->id,
'action_type' => 'checkout',
'item_id' => $item->id,
'item_type' => get_class($item),
'target_id' => $target->id,
'target_type' => get_class($target),
'created_at' => $faker->dateTime(),
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(Actionlog::class, 'accessory-checkout', function (Faker\Generator $faker) {
$company = factory(App\Models\Company::class)->create();
$user = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$target = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$item = factory(App\Models\Accessory::class)->create(['company_id' => $company->id]);
return [
'user_id' => $user->id,
'action_type' => 'checkout',
'item_id' => $item->id,
'item_type' => get_class($item),
'target_id' => $target->id,
'target_type' => get_class($target),
'created_at' => $faker->dateTime(),
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(Actionlog::class, 'consumable-checkout', function (Faker\Generator $faker) {
$company = factory(App\Models\Company::class)->create();
$user = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$target = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$item = factory(App\Models\Consumable::class)->create(['company_id' => $company->id]);
return [
'user_id' => $user->id,
'action_type' => 'checkout',
'item_id' => $item->id,
'item_type' => get_class($item),
'target_id' => $target->id,
'target_type' => get_class($target),
'created_at' => $faker->dateTime(),
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(Actionlog::class, 'component-checkout', function (Faker\Generator $faker) {
$company = factory(App\Models\Company::class)->create();
$user = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$target = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$item = factory(App\Models\Component::class)->create(['company_id' => $company->id]);
return [
'user_id' => $user->id,
'action_type' => 'checkout',
'item_id' => $item->id,
'item_type' => get_class($item),
'target_id' => $target->id,
'target_type' => get_class($target),
'created_at' => $faker->dateTime(),
'note' => $faker->sentence,
'company_id' => $company->id
];
});

View file

@ -0,0 +1,106 @@
<?php
use App\Models\Asset;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to modelling assets.
|
*/
$factory->define(Asset::class, function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'model_id' => function () {
return factory(App\Models\AssetModel::class)->create()->id;
},
'rtd_location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'serial' => $faker->uuid,
'status_id' => function () {
return factory(App\Models\Statuslabel::class)->states('rtd')->create()->id;
},
'user_id' => function () {
return factory(App\Models\User::class)->create()->id;
},
'asset_tag' => $faker->unixTime('now'),
'notes' => $faker->sentence,
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'order_number' => $faker->numberBetween(1000000, 50000000),
'supplier_id' => function () {
return factory(App\Models\Supplier::class)->create()->id;
},
'company_id' => function () {
return factory(App\Models\Company::class)->create()->id;
},
'requestable' => $faker->boolean()
];
});
$factory->state(Asset::class, 'deleted', function ($faker) {
return [
'deleted_at' => $faker->dateTime(),
];
});
$factory->state(Asset::class, 'assigned-to-user', function ($faker) {
return [
'assigned_to' => factory(App\Models\User::class)->create()->id,
'assigned_type' => App\Models\User::class,
];
});
$factory->state(Asset::class, 'assigned-to-location', function ($faker) {
return [
'assigned_to' => factory(App\Models\Location::class)->create()->id,
'assigned_type' => App\Models\Location::class,
];
});
$factory->state(Asset::class, 'assigned-to-asset', function ($faker) {
return [
'assigned_to' => factory(App\Models\Asset::class)->create()->id,
'assigned_type' => App\Models\Asset::class,
];
});
$factory->define(App\Models\AssetModel::class, function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'manufacturer_id' => function () {
return factory(App\Models\Manufacturer::class)->create()->id;
},
'category_id' => function () {
return factory(App\Models\Category::class)->states('asset-category')->create()->id;
},
'model_number' => $faker->numberBetween(1000000, 50000000),
'eol' => 1,
'notes' => $faker->paragraph(),
'requestable' => $faker->boolean(),
'depreciation_id' => function () {
return factory(App\Models\Depreciation::class)->create()->id;
},
];
});
$factory->define(App\Models\AssetMaintenance::class, function (Faker\Generator $faker) {
return [
'asset_id' => function () {
return factory(App\Models\Asset::class)->create()->id;
},
'supplier_id' => function () {
return factory(App\Models\Supplier::class)->create()->id;
},
'asset_maintenance_type' => $faker->randomElement(['maintenance', 'repair', 'upgrade']),
'title' => $faker->sentence,
'start_date' => $faker->date(),
'is_warranty' => $faker->boolean(),
'notes' => $faker->paragraph(),
];
});

View file

@ -0,0 +1,46 @@
<?php
/*
|--------------------------------------------------------------------------
| Category Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating categories and the various states..
|
*/
$factory->define(App\Models\Category::class, function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'category_type' => $faker->randomElement(['asset', 'accessory', 'component', 'consumable']),
'eula_text' => $faker->paragraph(),
'require_acceptance' => $faker->boolean(),
'use_default_eula' => $faker->boolean(),
'checkin_email' => $faker->boolean()
];
});
$factory->state(App\Models\Category::class, 'asset-category', function ($faker) {
return [
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'accessory-category', function ($faker) {
return [
'category_type' => 'accessory',
];
});
$factory->state(App\Models\Category::class, 'component-category', function ($faker) {
return [
'category_type' => 'component',
];
});
$factory->state(App\Models\Category::class, 'consumable-category', function ($faker) {
return [
'category_type' => 'consumable',
];
});

View file

@ -19,39 +19,150 @@ use App\Models\Manufacturer;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\Supplier; use App\Models\Supplier;
$factory->defineAs(App\Models\Asset::class, 'asset', function (Faker\Generator $faker) { $factory->define(App\Models\Accessory::class, function (Faker\Generator $faker) {
return [ return [
'name' => $faker->catchPhrase, 'company_id' => function () {
'model_id' => AssetModel::inRandomOrder()->first()->id, return factory(App\Models\Company::class)->create()->id;
'rtd_location_id' => Location::inRandomOrder()->first()->id, },
'serial' => $faker->uuid, 'name' => $faker->text(20),
'status_id' => Statuslabel::inRandomOrder()->first()->id, 'category_id' => function () {
'user_id' => 1, return factory(App\Models\Category::class)->states('accessory-category')->create()->id;
'asset_tag' => $faker->unixTime('now'), },
'notes' => $faker->sentence, 'manufacturer_id' => function () {
return factory(App\Models\Manufacturer::class)->create()->id;
},
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'order_number' => $faker->numberBetween(1000000, 50000000),
'purchase_date' => $faker->dateTime(), 'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2), 'purchase_cost' => $faker->randomFloat(2),
'order_number' => $faker->numberBetween(1000000, 50000000), 'qty' => $faker->numberBetween(5, 10),
'supplier_id' => Supplier::inRandomOrder()->first()->id, 'min_amt' => $faker->numberBetween($min = 1, $max = 2),
'company_id' => Company::inRandomOrder()->first()->id,
'requestable' => $faker->boolean()
]; ];
}); });
$factory->define(App\Models\Company::class, function (Faker\Generator $faker) {
return [
'name' => $faker->company,
];
});
$factory->defineAs(App\Models\AssetModel::class, 'assetmodel', function (Faker\Generator $faker) { $factory->define(App\Models\Component::class, function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'category_id' => function () {
return factory(App\Models\Category::class)->create()->id;
},
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'serial' => $faker->uuid,
'qty' => $faker->numberBetween(3, 10),
'order_number' => $faker->numberBetween(1000000, 50000000),
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'min_amt' => $faker->numberBetween($min = 1, $max = 2),
'company_id' => function () {
return factory(App\Models\Company::class)->create()->id;
},
];
});
$factory->define(App\Models\Consumable::class, function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'company_id' => function () {
return factory(App\Models\Company::class)->create()->id;
},
'category_id' => function () {
return factory(App\Models\Category::class)->create()->id;
},
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'manufacturer_id' => function () {
return factory(App\Models\Manufacturer::class)->create()->id;
},
'user_id' => function () {
return factory(App\Models\User::class)->create()->id;
},
'model_number' => $faker->numberBetween(1000000, 50000000),
'item_no' => $faker->numberBetween(1000000, 50000000),
'order_number' => $faker->numberBetween(1000000, 50000000),
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'qty' => $faker->numberBetween(5, 10),
'min_amt' => $faker->numberBetween($min = 1, $max = 2),
];
});
$factory->define(App\Models\CustomField::class, function (Faker\Generator $faker) {
return [ return [
'name' => $faker->catchPhrase, 'name' => $faker->catchPhrase,
'manufacturer_id' => Manufacturer::inRandomOrder()->first()->id, 'format' => 'IP',
'category_id' => Category::where('category_type', 'asset')->inRandomOrder()->first()->id, 'element' => 'text',
'model_number' => $faker->numberBetween(1000000, 50000000),
'eol' => 1,
'notes' => $faker->paragraph(),
'requestable' => $faker->boolean(),
]; ];
}); });
$factory->defineAs(App\Models\Location::class, 'location', function (Faker\Generator $faker) { $factory->define(App\Models\Department::class, function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'user_id' => '1',
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'company_id' => function () {
return factory(App\Models\Company::class)->create()->id;
},
'manager_id' => function () {
return factory(App\Models\User::class)->create()->id;
},
];
});
$factory->define(App\Models\Depreciation::class, function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'months' => $faker->numberBetween(1, 10),
];
});
$factory->define(App\Models\License::class, function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'serial' => $faker->uuid,
'seats' => $faker->numberBetween(1, 10),
'license_email' => $faker->safeEmail,
'license_name' => $faker->name,
'order_number' => $faker->numberBetween(1500, 13250),
'purchase_order' => $faker->numberBetween(1500, 13250),
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'notes' => $faker->sentence,
'supplier_id' => function () {
return factory(App\Models\Supplier::class)->create()->id;
},
'company_id' =>function () {
return factory(App\Models\Company::class)->create()->id;
},
];
});
$factory->define(App\Models\LicenseSeat::class, function (Faker\Generator $faker) {
return [
'license_id' => function () {
return factory(App\Models\License::class)->create()->id;
},
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'notes' => $faker->sentence,
'user_id' => '1',
];
});
$factory->define(App\Models\Location::class, function (Faker\Generator $faker) {
return [ return [
'name' => $faker->catchPhrase, 'name' => $faker->catchPhrase,
'address' => $faker->streetAddress, 'address' => $faker->streetAddress,
@ -64,69 +175,13 @@ $factory->defineAs(App\Models\Location::class, 'location', function (Faker\Gener
]; ];
}); });
$factory->defineAs(App\Models\Category::class, 'category', function (Faker\Generator $faker) { $factory->define(App\Models\Manufacturer::class, function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'category_type' => $faker->randomElement(['asset', 'accessory', 'component', 'consumable']),
'eula_text' => $faker->paragraph(),
'require_acceptance' => $faker->boolean(),
'use_default_eula' => $faker->boolean(),
'checkin_email' => $faker->boolean()
];
});
$factory->defineAs(App\Models\Company::class, 'company', function (Faker\Generator $faker) {
return [ return [
'name' => $faker->company, 'name' => $faker->company,
]; ];
}); });
$factory->defineAs(App\Models\Manufacturer::class, 'manufacturer', function (Faker\Generator $faker) { $factory->define(App\Models\Supplier::class, function (Faker\Generator $faker) {
return [
'name' => $faker->company,
];
});
$factory->defineAs(App\Models\Component::class, 'component', function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'category_id' => Category::where('category_type', 'component')->inRandomOrder()->first()->id,
'location_id' => Location::inRandomOrder()->first()->id,
'serial' => $faker->uuid,
'qty' => $faker->numberBetween(3, 10),
'order_number' => $faker->numberBetween(1000000, 50000000),
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'min_amt' => $faker->numberBetween($min = 1, $max = 2),
'company_id' => Company::inRandomOrder()->first()->id
];
});
$factory->defineAs(App\Models\Depreciation::class, 'depreciation', function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'months' => $faker->numberBetween(1, 10),
];
});
$factory->defineAs(App\Models\Accessory::class, 'accessory', function (Faker\Generator $faker) {
return [
'company_id' => Company::inRandomOrder()->first()->id,
'name' => $faker->text(20),
'category_id' => Category::where('category_type', 'accessory')->inRandomOrder()->first()->id,
'manufacturer_id' => Manufacturer::inRandomOrder()->first()->id,
'location_id' => Location::inRandomOrder()->first()->id,
'order_number' => $faker->numberBetween(1000000, 50000000),
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'qty' => $faker->numberBetween(5, 10),
'min_amt' => $faker->numberBetween($min = 1, $max = 2),
];
});
$factory->defineAs(App\Models\Supplier::class, 'supplier', function (Faker\Generator $faker) {
return [ return [
'name' => $faker->company, 'name' => $faker->company,
'address' => $faker->streetAddress, 'address' => $faker->streetAddress,
@ -144,230 +199,16 @@ $factory->defineAs(App\Models\Supplier::class, 'supplier', function (Faker\Gener
]; ];
}); });
$factory->define(App\Models\Setting::class, function ($faker) {
$factory->defineAs(App\Models\Consumable::class, 'consumable', function (Faker\Generator $faker) {
return [ return [
'name' => $faker->text(20), 'user_id' => 1,
'company_id' => Company::inRandomOrder()->first()->id, 'per_page' => 20,
'category_id' => Category::where('category_type', 'consumable')->inRandomOrder()->first()->id, 'site_name' => $faker->sentence,
'model_number' => $faker->numberBetween(1000000, 50000000), 'auto_increment_assets' => false,
'item_no' => $faker->numberBetween(1000000, 50000000), 'alert_email' => $faker->safeEmail(),
'order_number' => $faker->numberBetween(1000000, 50000000), 'alerts_enabled' => false,
'purchase_date' => $faker->dateTime(), 'brand' => 1,
'purchase_cost' => $faker->randomFloat(2), 'default_currency' => $faker->currencyCode,
'qty' => $faker->numberBetween(5, 10), 'locale' => $faker->locale,
'min_amt' => $faker->numberBetween($min = 1, $max = 2),
];
});
$factory->defineAs(App\Models\Statuslabel::class, 'rtd', function (Faker\Generator $faker) {
return [
'name' => 'Ready to Deploy',
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 1,
'pending' => 0,
'archived' => 0,
'notes' => ''
];
});
$factory->defineAs(App\Models\Statuslabel::class, 'pending', function (Faker\Generator $faker) {
return [
'name' => 'Pending',
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 0,
'pending' => 1,
'archived' => 0,
'notes' => $faker->sentence
];
});
$factory->defineAs(App\Models\Statuslabel::class, 'archived', function (Faker\Generator $faker) {
return [
'name' => 'Archived',
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 0,
'pending' => 0,
'archived' => 1,
'notes' => 'These assets are permanently undeployable'
];
});
$factory->defineAs(App\Models\Statuslabel::class, 'out_for_diagnostics', function (Faker\Generator $faker) {
return [
'name' => 'Out for Diagnostics',
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 0,
'pending' => 0,
'archived' => 0,
'notes' => ''
];
});
$factory->defineAs(App\Models\Statuslabel::class, 'out_for_repair', function (Faker\Generator $faker) {
return [
'name' => 'Out for Repair',
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 0,
'pending' => 0,
'archived' => 0,
'notes' => ''
];
});
$factory->defineAs(App\Models\Statuslabel::class, 'broken', function (Faker\Generator $faker) {
return [
'name' => 'Broken - Not Fixable',
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 0,
'pending' => 0,
'archived' => 1,
'notes' => ''
];
});
$factory->defineAs(App\Models\Statuslabel::class, 'lost', function (Faker\Generator $faker) {
return [
'name' => 'Lost/Stolen',
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 0,
'pending' => 0,
'archived' => 1,
'notes' => '',
];
});
$factory->defineAs(App\Models\License::class, 'license', function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'serial' => $faker->uuid,
'seats' => $faker->numberBetween(1, 10),
'license_email' => $faker->safeEmail,
'license_name' => $faker->name,
'order_number' => $faker->numberBetween(1500, 13250),
'purchase_order' => $faker->numberBetween(1500, 13250),
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'notes' => $faker->sentence,
'supplier_id' => Supplier::inRandomOrder()->first()->id,
'company_id' => Company::inRandomOrder()->first()->id
];
});
$factory->defineAs(App\Models\LicenseSeat::class, 'license-seat', function (Faker\Generator $faker) {
return [
'license_id' => $faker->numberBetween(1, 10),
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'notes' => $faker->sentence,
'user_id' => '1',
];
});
$factory->defineAs(App\Models\Actionlog::class, 'asset-checkout', function (Faker\Generator $faker) {
$company = Company::has('users')->has('assets')->inRandomOrder()->first();
return [
'user_id' => $company->users()->inRandomOrder()->first()->id,
'action_type' => 'checkout',
'item_id' => $company->assets()->inRandomOrder()->first()->id,
'target_id' => $company->users()->inRandomOrder()->first()->id,
'target_type' => 'App\\Models\\User',
'created_at' => $faker->dateTime(),
'item_type' => 'App\\Models\\Asset',
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(App\Models\Actionlog::class, 'license-checkout-asset', function (Faker\Generator $faker) {
$company = Company::has('users')->has('licenses')->inRandomOrder()->first();
return [
'user_id' => $company->users()->inRandomOrder()->first()->id,
'action_type' => 'checkout',
'item_id' => $company->licenses()->whereNotNull('company_id')->inRandomOrder()->first()->id,
'target_id' => $company->assets()->inRandomOrder()->first()->id,
'target_type' => 'App\\Models\\Asset',
'created_at' => $faker->dateTime(),
'item_type' => 'App\\Models\\License',
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(App\Models\Actionlog::class, 'accessory-checkout', function (Faker\Generator $faker) {
$company = Company::has('users')->has('accessories')->inRandomOrder()->first();
return [
'user_id' => $company->users()->inRandomOrder()->first()->id,
'action_type' => 'checkout',
'item_id' => $company->accessories()->whereNotNull('company_id')->inRandomOrder()->first()->id,
'target_id' => $company->users()->inRandomOrder()->first()->id,
'target_type' => 'App\\Models\\User',
'created_at' => $faker->dateTime(),
'item_type' => 'App\\Models\\Accessory',
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(App\Models\Actionlog::class, 'consumable-checkout', function (Faker\Generator $faker) {
$company = Company::has('users')->has('consumables')->inRandomOrder()->first();
return [
'user_id' => $company->users()->inRandomOrder()->first()->id,
'action_type' => 'checkout',
'item_id' => $company->consumables()->whereNotNull('company_id')->inRandomOrder()->first()->id,
'target_id' => $company->users()->inRandomOrder()->first()->id,
'target_type' => 'App\\Models\\User',
'created_at' => $faker->dateTime(),
'item_type' => 'App\\Models\\Consumable',
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(App\Models\Actionlog::class, 'component-checkout', function (Faker\Generator $faker) {
$company = Company::has('users')->has('components')->inRandomOrder()->first();
return [
'user_id' => $company->users()->inRandomOrder()->first()->id,
'action_type' => 'checkout',
'item_id' => $company->components()->whereNotNull('company_id')->inRandomOrder()->first()->id,
'target_id' => $company->users()->inRandomOrder()->first()->id,
'target_type' => 'App\\Models\\User',
'created_at' => $faker->dateTime(),
'item_type' => 'App\\Models\\Component',
'note' => $faker->sentence,
'company_id' => $company->id
];
});
$factory->defineAs(App\Models\CustomField::class, 'customfield-ip', function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'format' => 'IP',
'element' => 'text',
]; ];
}); });

View file

@ -0,0 +1,60 @@
<?php
use App\Models\Statuslabel;
$factory->define(Statuslabel::class, function (Faker\Generator $faker) {
return [
'name' => $faker->sentence,
'created_at' => $faker->dateTime(),
'updated_at' => $faker->dateTime(),
'user_id' => 1,
'deleted_at' => null,
'deployable' => 0,
'pending' => 0,
'archived' => 0,
'notes' => ''
];
});
$factory->state(Statuslabel::class, 'rtd', function (Faker\Generator $faker) {
return [
'notes' => $faker->sentence,
'deployable' => 1
];
});
$factory->state(Statuslabel::class, 'pending', function (Faker\Generator $faker) {
return [
'notes' => $faker->sentence,
'pending' => 1,
];
});
$factory->state(Statuslabel::class, 'archived', function (Faker\Generator $faker) {
return [
'notes' => 'These assets are permanently undeployable',
'archived' => 1,
];
});
$factory->state(Statuslabel::class, 'out_for_diagnostics', function (Faker\Generator $faker) {
return [
'name' => 'Out for Diagnostics',
];
});
$factory->state(Statuslabel::class, 'out_for_repair', function (Faker\Generator $faker) {
return [
'name' => 'Out for Repair',
];
});
$factory->state(Statuslabel::class, 'broken', function (Faker\Generator $faker) {
return [
'name' => 'Broken - Not Fixable',
];
});
$factory->state(Statuslabel::class, 'lost', function (Faker\Generator $faker) {
return [
'name' => 'Lost/Stolen',
];
});

View file

@ -2,26 +2,31 @@
use App\Models\Company; use App\Models\Company;
$factory->defineAs(App\Models\User::class, 'valid-user', function (Faker\Generator $faker) { $factory->define(App\Models\User::class, function (Faker\Generator $faker) {
return [ return [
'first_name' => $faker->firstName, 'first_name' => $faker->firstName,
'last_name' => $faker->lastName, 'last_name' => $faker->lastName,
'username' => $faker->username, 'username' => $faker->username,
'password' => $faker->password, 'password' => $faker->password,
'permissions' => '{"user":"0"}', 'permissions' => '{"user":"0"}',
'email' => $faker->safeEmail, 'email' => $faker->safeEmail,
'company_id' => Company::inRandomOrder()->first()->id, 'company_id' => function () {
'locale' => $faker->locale, return factory(App\Models\Company::class)->create()->id;
'employee_num' => $faker->numberBetween(3500, 35050), },
'jobtitle' => $faker->word, 'locale' => $faker->locale,
'phone' => $faker->phoneNumber, 'employee_num' => $faker->numberBetween(3500, 35050),
'notes' => $faker->sentence 'jobtitle' => $faker->word,
'phone' => $faker->phoneNumber,
'notes' => $faker->sentence,
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
]; ];
}); });
// USER GLOBAL PERMISSION STATES // USER GLOBAL PERMISSION STATES
$factory->state(App\Models\User::class, 'superuser', function ($faker) { $factory->state(App\Models\User::class, 'superuser', function ($faker) {
return [ return [
'permissions' => '{"superuser":"1"}', 'permissions' => '{"superuser":"1"}',
]; ];
}); });
@ -33,7 +38,7 @@ $factory->state(App\Models\User::class, 'admin', function ($faker) {
// USER ASSET PERMISSION STATES // USER ASSET PERMISSION STATES
$factory->state(App\Models\User::class, 'view-assets', function ($faker) { $factory->state(App\Models\User::class, 'view-assets', function ($faker) {
return [ return [
'permissions' => '{"assets.view":"1"}', 'permissions' => '{"assets.view":"1"}',
]; ];
}); });
@ -51,7 +56,7 @@ $factory->state(App\Models\User::class, 'edit-assets', function ($faker) {
$factory->state(App\Models\User::class, 'delete-assets', function ($faker) { $factory->state(App\Models\User::class, 'delete-assets', function ($faker) {
return [ return [
'permissions' => '{"assets.delete":"1",}', 'permissions' => '{"assets.delete":"1"}',
]; ];
}); });
@ -76,7 +81,7 @@ $factory->state(App\Models\User::class, 'view-requestable-assets', function ($fa
// USER ACCESSORY PERMISSION STATES // USER ACCESSORY PERMISSION STATES
$factory->state(App\Models\User::class, 'view-accessories', function ($faker) { $factory->state(App\Models\User::class, 'view-accessories', function ($faker) {
return [ return [
'permissions' => '{"accessories.view":"1"}', 'permissions' => '{"accessories.view":"1"}',
]; ];
}); });
@ -94,7 +99,7 @@ $factory->state(App\Models\User::class, 'edit-accessories', function ($faker) {
$factory->state(App\Models\User::class, 'delete-accessories', function ($faker) { $factory->state(App\Models\User::class, 'delete-accessories', function ($faker) {
return [ return [
'permissions' => '{"accessories.delete":"1",}', 'permissions' => '{"accessories.delete":"1"}',
]; ];
}); });
@ -113,7 +118,7 @@ $factory->state(App\Models\User::class, 'checkout-accessories', function ($faker
// USER CONSUMABLE PERMISSION STATES // USER CONSUMABLE PERMISSION STATES
$factory->state(App\Models\User::class, 'view-consumables', function ($faker) { $factory->state(App\Models\User::class, 'view-consumables', function ($faker) {
return [ return [
'permissions' => '{"consumables.view":"1"}', 'permissions' => '{"consumables.view":"1"}',
]; ];
}); });
@ -131,7 +136,7 @@ $factory->state(App\Models\User::class, 'edit-consumables', function ($faker) {
$factory->state(App\Models\User::class, 'delete-consumables', function ($faker) { $factory->state(App\Models\User::class, 'delete-consumables', function ($faker) {
return [ return [
'permissions' => '{"consumables.delete":"1",}', 'permissions' => '{"consumables.delete":"1"}',
]; ];
}); });
@ -150,7 +155,7 @@ $factory->state(App\Models\User::class, 'checkout-consumables', function ($faker
// USER LICENSE PERMISSION STATES // USER LICENSE PERMISSION STATES
$factory->state(App\Models\User::class, 'view-licenses', function ($faker) { $factory->state(App\Models\User::class, 'view-licenses', function ($faker) {
return [ return [
'permissions' => '{"licenses.view":"1"}', 'permissions' => '{"licenses.view":"1"}',
]; ];
}); });
@ -168,7 +173,7 @@ $factory->state(App\Models\User::class, 'edit-licenses', function ($faker) {
$factory->state(App\Models\User::class, 'delete-licenses', function ($faker) { $factory->state(App\Models\User::class, 'delete-licenses', function ($faker) {
return [ return [
'permissions' => '{"licenses.delete":"1",}', 'permissions' => '{"licenses.delete":"1"}',
]; ];
}); });
@ -187,7 +192,7 @@ $factory->state(App\Models\User::class, 'view-keys-licenses', function ($faker)
// USER COMPONENTS PERMISSION STATES // USER COMPONENTS PERMISSION STATES
$factory->state(App\Models\User::class, 'view-components', function ($faker) { $factory->state(App\Models\User::class, 'view-components', function ($faker) {
return [ return [
'permissions' => '{"components.view":"1"}', 'permissions' => '{"components.view":"1"}',
]; ];
}); });
@ -205,7 +210,7 @@ $factory->state(App\Models\User::class, 'edit-components', function ($faker) {
$factory->state(App\Models\User::class, 'delete-components', function ($faker) { $factory->state(App\Models\User::class, 'delete-components', function ($faker) {
return [ return [
'permissions' => '{"components.delete":"1",}', 'permissions' => '{"components.delete":"1"}',
]; ];
}); });
@ -224,7 +229,7 @@ $factory->state(App\Models\User::class, 'checkout-components', function ($faker)
// USER USER PERMISSION STATES // USER USER PERMISSION STATES
$factory->state(App\Models\User::class, 'view-users', function ($faker) { $factory->state(App\Models\User::class, 'view-users', function ($faker) {
return [ return [
'permissions' => '{"users.view":"1"}', 'permissions' => '{"users.view":"1"}',
]; ];
}); });
@ -242,6 +247,6 @@ $factory->state(App\Models\User::class, 'edit-users', function ($faker) {
$factory->state(App\Models\User::class, 'delete-users', function ($faker) { $factory->state(App\Models\User::class, 'delete-users', function ($faker) {
return [ return [
'permissions' => '{"users.delete":"1",}', 'permissions' => '{"users.delete":"1"}',
]; ];
}); });

View file

@ -7,6 +7,6 @@ class AccessorySeeder extends Seeder
public function run() public function run()
{ {
Accessory::truncate(); Accessory::truncate();
factory(Accessory::class, 'accessory',15)->create(); factory(Accessory::class,15)->create();
} }
} }

View file

@ -8,9 +8,9 @@ class ActionlogSeeder extends Seeder
{ {
Actionlog::truncate(); Actionlog::truncate();
factory(Actionlog::class, 'asset-checkout',25)->create(); factory(Actionlog::class, 'asset-checkout',25)->create();
factory(Actionlog::class, 'accessory-checkout',15)->create(); // factory(Actionlog::class, 'accessory-checkout',15)->create();
factory(Actionlog::class, 'consumable-checkout', 15)->create(); // factory(Actionlog::class, 'consumable-checkout', 15)->create();
factory(Actionlog::class, 'component-checkout', 15)->create(); // factory(Actionlog::class, 'component-checkout', 15)->create();
factory(Actionlog::class, 'license-checkout-asset', 15)->create(); // factory(Actionlog::class, 'license-checkout-asset', 15)->create();
} }
} }

View file

@ -8,7 +8,7 @@ class AssetModelSeeder extends Seeder
public function run() public function run()
{ {
AssetModel::truncate(); AssetModel::truncate();
factory(AssetModel::class, 'assetmodel',5)->create(); factory(AssetModel::class,5)->create();
} }
} }

View file

@ -8,10 +8,6 @@ class AssetSeeder extends Seeder
public function run() public function run()
{ {
Asset::truncate(); Asset::truncate();
factory(Asset::class, 'asset', 100)->create(); factory(Asset::class, 100)->create();
// factory(App\Models\Asset::class, 50)->create()->each(function($u) {
// $u->assetmodel()->save(factory(App\AssetModel::class)->make());
// });
} }
} }

View file

@ -7,10 +7,10 @@ class CategorySeeder extends Seeder
public function run() public function run()
{ {
Category::truncate(); Category::truncate();
factory(Category::class, 'category', 10)->create(['category_type' => 'asset']); factory(Category::class, 10)->states('asset-category')->create();
factory(Category::class, 'category', 10)->create(['category_type' => 'accessory']); factory(Category::class, 10)->states('accessory-category')->create();
factory(Category::class, 'category', 10)->create(['category_type' => 'consumable']); factory(Category::class, 10)->states('component-category')->create();
factory(Category::class, 'category', 10)->create(['category_type' => 'component']); factory(Category::class, 10)->states('consumable-category')->create();
} }
} }

View file

@ -14,6 +14,6 @@ class CompanySeeder extends Seeder
{ {
// //
Company::truncate(); Company::truncate();
factory(Company::class, 'company', 4)->create(); factory(Company::class, 4)->create();
} }
} }

View file

@ -4,10 +4,10 @@ use App\Models\Component;
class ComponentSeeder extends Seeder class ComponentSeeder extends Seeder
{ {
public function run() public function run()
{ {
Component::truncate(); Component::truncate();
DB::table('components_assets')->truncate(); DB::table('components_assets')->truncate();
factory(Component::class, 'component',10)->create(); factory(Component::class, 10)->create();
} }
} }

View file

@ -4,9 +4,9 @@ use App\Models\Consumable;
class ConsumableSeeder extends Seeder class ConsumableSeeder extends Seeder
{ {
public function run() public function run()
{ {
Consumable::truncate(); Consumable::truncate();
factory(Consumable::class, 'consumable',25)->create(); factory(Consumable::class, 25)->create();
} }
} }

View file

@ -4,9 +4,9 @@ use App\Models\Depreciation;
class DepreciationSeeder extends Seeder class DepreciationSeeder extends Seeder
{ {
public function run() public function run()
{ {
Depreciation::truncate(); Depreciation::truncate();
factory(Depreciation::class, 'depreciation')->create(); factory(Depreciation::class, 5)->create();
} }
} }

View file

@ -3,19 +3,14 @@ use Illuminate\Database\Seeder;
use App\Models\License; use App\Models\License;
use App\Models\LicenseSeat; use App\Models\LicenseSeat;
class LicenseSeeder extends Seeder class LicenseSeeder extends Seeder
{ {
public function run() public function run()
{ {
License::truncate(); License::truncate();
factory(License::class, 'license', 10)->create(); factory(License::class, 10)->create();
LicenseSeat::truncate(); LicenseSeat::truncate();
factory(LicenseSeat::class, 'license-seat', 10)->create(); factory(LicenseSeat::class, 10)->create();
}
// factory(App\Models\Asset::class, 50)->create()->each(function($u) {
// $u->assetmodel()->save(factory(App\AssetModel::class)->make());
// });
}
} }

View file

@ -5,10 +5,9 @@ use App\Models\Location;
class LocationSeeder extends Seeder class LocationSeeder extends Seeder
{ {
public function run() public function run()
{ {
Location::truncate(); Location::truncate();
factory(Location::class, 'location', 5)->create(); factory(Location::class, 5)->create();
}
}
} }

View file

@ -7,7 +7,6 @@ class ManufacturerSeeder extends Seeder
public function run() public function run()
{ {
Manufacturer::truncate(); Manufacturer::truncate();
factory(Manufacturer::class, 'manufacturer', 10)->create(); factory(Manufacturer::class, 10)->create();
} }
} }

View file

@ -7,14 +7,13 @@ class StatuslabelSeeder extends Seeder
{ {
public function run() public function run()
{ {
Statuslabel::truncate(); Statuslabel::truncate();
factory(Statuslabel::class, 'rtd')->create(); factory(Statuslabel::class)->states('rtd')->create(['name' => "Ready to Deploy"]);
factory(Statuslabel::class, 'pending')->create(); factory(Statuslabel::class)->states('pending')->create(['name' => "Pending"]);
factory(Statuslabel::class, 'archived')->create(); factory(Statuslabel::class)->states('archived')->create(['name' => "Archived"]);
factory(Statuslabel::class, 'out_for_diagnostics')->create(); factory(Statuslabel::class)->states('out_for_diagnostics')->create();
factory(Statuslabel::class, 'out_for_repair')->create(); factory(Statuslabel::class)->states('out_for_repair')->create();
factory(Statuslabel::class, 'broken')->create(); factory(Statuslabel::class)->states('broken')->create();
factory(Statuslabel::class, 'lost')->create(); factory(Statuslabel::class)->states('lost')->create();
} }
} }

View file

@ -6,8 +6,7 @@ class SupplierSeeder extends Seeder
{ {
public function run() public function run()
{ {
Supplier::truncate(); Supplier::truncate();
factory(Supplier::class, 'supplier',5)->create(); factory(Supplier::class, 5)->create();
} }
} }

View file

@ -13,6 +13,6 @@ class UserSeeder extends Seeder
public function run() public function run()
{ {
// Don't truncate the user column, that might suck. // Don't truncate the user column, that might suck.
factory(User::class, 'valid-user', 10)->create(); factory(User::class, 10)->create();
} }
} }

View file

@ -23,5 +23,7 @@
<env name="CACHE_DRIVER" value="array"/> <env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/> <env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite_testing" />
</php> </php>
</phpunit> </phpunit>

View file

@ -26,7 +26,7 @@
name="location_users" name="location_users"
id="table-users" id="table-users"
class="table table-striped snipe-table" class="table table-striped snipe-table"
data-url="{{route('api.locations.viewusers', $location->id)}}" data-url="{{route('api.users.index', ['location_id' => $location->id]) }}"
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"
data-cookie-id-table="location_usersDetailTable"> data-cookie-id-table="location_usersDetailTable">
@ -54,7 +54,7 @@
<table <table
name="location_assets" name="location_assets"
id="table-assets" id="table-assets"
data-url="{{route('api.locations.viewassets', $location->id)}}" data-url="{{route('api.assets.index', ['location_id' => $location->id]) }}"
class="table table-striped snipe-table" class="table table-striped snipe-table"
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"

View file

@ -295,20 +295,6 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
Route::group(['prefix' => 'locations'], function () { Route::group(['prefix' => 'locations'], function () {
Route::get('{location}/users',
[
'as'=>'api.locations.viewusers',
'uses'=>'LocationsController@getDataViewUsers'
]
);
Route::get('{location}/assets',
[
'as'=>'api.locations.viewassets',
'uses'=>'LocationsController@getDataViewAssets'
]
);
// Do we actually still need this, now that we have an API? // Do we actually still need this, now that we have an API?
Route::get('{location}/check', Route::get('{location}/check',
[ [

File diff suppressed because one or more lines are too long

View file

@ -21,7 +21,7 @@ class ApiAssetsCest
$I->wantTo('Get a list of assets'); $I->wantTo('Get a list of assets');
// setup // setup
$assets = factory(\App\Models\Asset::class, 'asset', 10)->create(); $assets = factory(\App\Models\Asset::class, 10)->create();
// call // call
$I->sendGET('/hardware'); $I->sendGET('/hardware');
@ -121,7 +121,7 @@ class ApiAssetsCest
{ {
$I->wantTo('Create a new asset'); $I->wantTo('Create a new asset');
$temp_asset = factory(\App\Models\Asset::class, 'asset')->make(); $temp_asset = factory(\App\Models\Asset::class)->make();
// setup // setup
$data = [ $data = [
@ -153,10 +153,10 @@ class ApiAssetsCest
$I->wantTo('Update an asset with PATCH'); $I->wantTo('Update an asset with PATCH');
// create // create
$asset = factory(\App\Models\Asset::class, 'asset')->create(); $asset = factory(\App\Models\Asset::class)->create();
$I->assertInstanceOf(\App\Models\Asset::class, $asset); $I->assertInstanceOf(\App\Models\Asset::class, $asset);
$temp_asset = factory(\App\Models\Asset::class, 'asset')->make(); $temp_asset = factory(\App\Models\Asset::class)->make();
$data = [ $data = [
'asset_tag' => $temp_asset->asset_tag, 'asset_tag' => $temp_asset->asset_tag,
@ -279,11 +279,11 @@ class ApiAssetsCest
$I->wantTo('Update a asset with PUT'); $I->wantTo('Update a asset with PUT');
// create // create
$asset = factory(\App\Models\Asset::class, 'asset')->create(); $asset = factory(\App\Models\Asset::class)->create();
$I->assertInstanceOf(\App\Models\Asset::class, $asset); $I->assertInstanceOf(\App\Models\Asset::class, $asset);
$temp_asset_tag = $this->faker->uuid; $temp_asset_tag = $this->faker->uuid;
$temp_asset = factory(\App\Models\Asset::class, 'asset')->make([ $temp_asset = factory(\App\Models\Asset::class)->make([
'asset_tag' => $temp_asset_tag, 'asset_tag' => $temp_asset_tag,
]); ]);
@ -411,7 +411,7 @@ class ApiAssetsCest
$I->wantTo('Delete an asset'); $I->wantTo('Delete an asset');
// create // create
$asset = factory(\App\Models\Asset::class, 'asset')->create(); $asset = factory(\App\Models\Asset::class)->create();
$I->assertInstanceOf(\App\Models\Asset::class, $asset); $I->assertInstanceOf(\App\Models\Asset::class, $asset);
// delete // delete

View file

@ -19,11 +19,11 @@ class ApiComponentsAssetsCest
$I->wantTo('Get a list of assets related to a component'); $I->wantTo('Get a list of assets related to a component');
// generate component // generate component
$component = factory(\App\Models\Component::class, 'component') $component = factory(\App\Models\Component::class)
->create(['user_id' => $this->user->id, 'qty' => 20]); ->create(['user_id' => $this->user->id, 'qty' => 20]);
// generate assets and associate component // generate assets and associate component
$assets = factory(\App\Models\Asset::class, 'asset', 2) $assets = factory(\App\Models\Asset::class, 2)
->create(['user_id' => $this->user->id]) ->create(['user_id' => $this->user->id])
->each(function ($asset) use ($component) { ->each(function ($asset) use ($component) {
$component->assets()->attach($component->id, [ $component->assets()->attach($component->id, [
@ -65,7 +65,7 @@ class ApiComponentsAssetsCest
{ {
$I->wantTo('See an empty response when there are no associated assets to a component'); $I->wantTo('See an empty response when there are no associated assets to a component');
$component = factory(\App\Models\Component::class, 'component') $component = factory(\App\Models\Component::class)
->create(['user_id' => $this->user->id, 'qty' => 20]); ->create(['user_id' => $this->user->id, 'qty' => 20]);
$I->sendGET('/components/' . $component->id . '/assets'); $I->sendGET('/components/' . $component->id . '/assets');

View file

@ -21,7 +21,7 @@ class ApiComponentsCest
$I->wantTo('Get a list of components'); $I->wantTo('Get a list of components');
// setup // setup
$components = factory(\App\Models\Component::class, 'component', 10)->create(); $components = factory(\App\Models\Component::class, 10)->create();
// call // call
$I->sendGET('/components'); $I->sendGET('/components');
@ -46,9 +46,9 @@ class ApiComponentsCest
$I->wantTo('Create a new component'); $I->wantTo('Create a new component');
// setup // setup
$category = factory(\App\Models\Category::class, 'category')->create(['user_id' => $this->user->id]); $category = factory(\App\Models\Category::class)->create(['user_id' => $this->user->id]);
$location = factory(\App\Models\Location::class, 'location')->create(['user_id' => $this->user->id]); $location = factory(\App\Models\Location::class)->create(['user_id' => $this->user->id]);
$company = factory(\App\Models\Company::class, 'company')->create(); $company = factory(\App\Models\Company::class)->create();
$data = [ $data = [
'category_id' => $category->id, 'category_id' => $category->id,
@ -107,7 +107,7 @@ class ApiComponentsCest
$I->wantTo('Update a component with PATCH'); $I->wantTo('Update a component with PATCH');
// create // create
$component = factory(\App\Models\Component::class, 'component')->create(); $component = factory(\App\Models\Component::class)->create();
$I->assertInstanceOf(\App\Models\Component::class, $component); $I->assertInstanceOf(\App\Models\Component::class, $component);
$data = [ $data = [
@ -142,7 +142,7 @@ class ApiComponentsCest
$I->wantTo('Update a component with PUT'); $I->wantTo('Update a component with PUT');
// create // create
$component = factory(\App\Models\Component::class, 'component')->create(); $component = factory(\App\Models\Component::class)->create();
$I->assertInstanceOf(\App\Models\Component::class, $component); $I->assertInstanceOf(\App\Models\Component::class, $component);
$data = [ $data = [
@ -176,7 +176,7 @@ class ApiComponentsCest
$I->wantTo('Delete a component'); $I->wantTo('Delete a component');
// create // create
$component = factory(\App\Models\Component::class, 'component')->create(); $component = factory(\App\Models\Component::class)->create();
$I->assertInstanceOf(\App\Models\Component::class, $component); $I->assertInstanceOf(\App\Models\Component::class, $component);
// delete // delete

View file

@ -53,7 +53,7 @@ class AccessoriesCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$accessory = factory(App\Models\Accessory::class,'accessory')->make(); $accessory = factory(App\Models\Accessory::class)->make();
$values = [ $values = [
'company_id' => $accessory->company_id, 'company_id' => $accessory->company_id,
'name' => $accessory->name, 'name' => $accessory->name,

View file

@ -33,7 +33,7 @@ class AssetModelsCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$model = factory(App\Models\AssetModel::class, 'assetmodel')->make(); $model = factory(App\Models\AssetModel::class)->make();
$values = [ $values = [
'name' => $model->name, 'name' => $model->name,
'manufacturer_id' => $model->manufacturer_id, 'manufacturer_id' => $model->manufacturer_id,
@ -56,7 +56,7 @@ class AssetModelsCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete an asset model'); $I->wantTo('Ensure I can delete an asset model');
$model = factory(App\Models\AssetModel::class, 'assetmodel')->create(); $model = factory(App\Models\AssetModel::class)->create();
$I->sendDelete(route('models.destroy', $model->id), ['_token' => csrf_token()]); $I->sendDelete(route('models.destroy', $model->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -33,7 +33,7 @@ class AssetsCest
public function passesCreateAndCheckout(FunctionalTester $I) public function passesCreateAndCheckout(FunctionalTester $I)
{ {
$asset = factory(App\Models\Asset::class,'asset')->make(); $asset = factory(App\Models\Asset::class)->make();
$userId = $I->getUserId(); $userId = $I->getUserId();
$values = [ $values = [
'company_id' => $asset->company_id, 'company_id' => $asset->company_id,

View file

@ -37,7 +37,7 @@ class CategoriesCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$category = factory(App\Models\Category::class, 'category')->make(); $category = factory(App\Models\Category::class)->make();
$values = [ $values = [
'name' => $category->name, 'name' => $category->name,
'category_type' => $category->category_type, 'category_type' => $category->category_type,
@ -55,7 +55,7 @@ class CategoriesCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a category'); $I->wantTo('Ensure I can delete a category');
$category = factory(App\Models\Category::class, 'category')->create(); $category = factory(App\Models\Category::class)->create();
$I->sendDelete(route('categories.destroy', $category->id), ['_token' => csrf_token()]); $I->sendDelete(route('categories.destroy', $category->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -32,7 +32,7 @@ class CompaniesCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$company = factory(App\Models\Company::class, 'company')->make(); $company = factory(App\Models\Company::class)->make();
$values = [ $values = [
'name' => $company->name 'name' => $company->name
]; ];

View file

@ -47,7 +47,7 @@ class ComponentsCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$component = factory(App\Models\Component::class, 'component')->make(); $component = factory(App\Models\Component::class)->make();
$values = [ $values = [
'name' => $component->name, 'name' => $component->name,

View file

@ -48,7 +48,7 @@ class ConsumablesCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$consumable = factory(App\Models\Consumable::class, 'consumable')->make(); $consumable = factory(App\Models\Consumable::class)->make();
$values = [ $values = [
'company_id' => $consumable->company_id, 'company_id' => $consumable->company_id,
'name' => $consumable->name, 'name' => $consumable->name,

View file

@ -44,7 +44,7 @@ class DepreciationCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$depreciation = factory(App\Models\Depreciation::class, 'depreciation')->make(); $depreciation = factory(App\Models\Depreciation::class)->make();
$values = [ $values = [
'name' => $depreciation->name, 'name' => $depreciation->name,
'months' => $depreciation->months 'months' => $depreciation->months

View file

@ -47,7 +47,7 @@ class LicensesCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$license = factory(App\Models\License::class, 'license')->make(); $license = factory(App\Models\License::class)->make();
$values = [ $values = [
'name' => $license->name, 'name' => $license->name,
'serial' => $license->serial, 'serial' => $license->serial,

View file

@ -45,7 +45,7 @@ class LocationsCest
} }
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$location = factory(App\Models\Location::class, 'location')->make(); $location = factory(App\Models\Location::class)->make();
$values = [ $values = [
'name' => $location->name, 'name' => $location->name,
'parent_id' => $I->getLocationId(), 'parent_id' => $I->getLocationId(),
@ -67,7 +67,7 @@ class LocationsCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a location'); $I->wantTo('Ensure I can delete a location');
$location = factory(App\Models\Location::class, 'location')->create(); $location = factory(App\Models\Location::class)->create();
$I->sendDelete(route('locations.destroy', $location->id), ['_token' => csrf_token()]); $I->sendDelete(route('locations.destroy', $location->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -43,7 +43,7 @@ class ManufacturersCest
} }
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$manufacturer = factory(App\Models\Manufacturer::class, 'manufacturer')->make(); $manufacturer = factory(App\Models\Manufacturer::class)->make();
$values = [ $values = [
'name' => $manufacturer->name 'name' => $manufacturer->name
]; ];
@ -57,7 +57,7 @@ class ManufacturersCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a manufacturer'); $I->wantTo('Ensure I can delete a manufacturer');
$manufacturerId = factory(App\Models\Manufacturer::class, 'manufacturer')->create()->id; $manufacturerId = factory(App\Models\Manufacturer::class)->create()->id;
$I->sendDelete(route('manufacturers.destroy', $manufacturerId), ['_token' => csrf_token()]); $I->sendDelete(route('manufacturers.destroy', $manufacturerId), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -34,7 +34,7 @@ class StatusLabelsCest
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$status = factory(App\Models\Statuslabel::class, 'pending')->make(); $status = factory(App\Models\Statuslabel::class)->states('pending')->make();
$submitValues = [ $submitValues = [
'name' => 'Testing Status', 'name' => 'Testing Status',
'statuslabel_types' => 'pending', 'statuslabel_types' => 'pending',

View file

@ -40,7 +40,7 @@ class SuppliersCest
} }
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$supplier = factory(App\Models\Supplier::class, 'supplier')->make(); $supplier = factory(App\Models\Supplier::class)->make();
$values = [ $values = [
'name' => $supplier->name, 'name' => $supplier->name,
'address' => $supplier->address, 'address' => $supplier->address,
@ -66,7 +66,7 @@ class SuppliersCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a supplier'); $I->wantTo('Ensure I can delete a supplier');
$supplier = factory(App\Models\Supplier::class, 'supplier')->create(); $supplier = factory(App\Models\Supplier::class)->create();
$I->sendDelete(route('suppliers.destroy', $supplier->id), ['_token' => csrf_token()]); $I->sendDelete(route('suppliers.destroy', $supplier->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -49,7 +49,7 @@ class UsersCest
} }
public function passesCorrectValidation(FunctionalTester $I) public function passesCorrectValidation(FunctionalTester $I)
{ {
$user = factory(App\Models\User::class, 'valid-user')->make(); $user = factory(App\Models\User::class)->make();
$submitValues = [ $submitValues = [
'first_name' => $user->first_name, 'first_name' => $user->first_name,
'last_name' => $user->last_name, 'last_name' => $user->last_name,
@ -61,8 +61,8 @@ class UsersCest
'locale' => $user->locale, 'locale' => $user->locale,
'employee_num' => $user->employee_num, 'employee_num' => $user->employee_num,
'jobtitle' => $user->jobtitle, 'jobtitle' => $user->jobtitle,
'manager_id' => 19, 'manager_id' => $user->manager_id,
'location_id' => 67, 'location_id' => $user->location_id,
'phone' => $user->phone, 'phone' => $user->phone,
'activated' => true, 'activated' => true,
'notes' => $user->notes 'notes' => $user->notes
@ -76,8 +76,8 @@ class UsersCest
'locale' => $user->locale, 'locale' => $user->locale,
'employee_num' => $user->employee_num, 'employee_num' => $user->employee_num,
'jobtitle' => $user->jobtitle, 'jobtitle' => $user->jobtitle,
'manager_id' => 19, 'manager_id' => $user->manager_id,
'location_id' => 67, 'location_id' => $user->location_id,
'phone' => $user->phone, 'phone' => $user->phone,
'activated' => true, 'activated' => true,
'notes' => $user->notes 'notes' => $user->notes
@ -91,7 +91,7 @@ class UsersCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$user = factory(App\Models\User::class, 'valid-user')->create(); $user = factory(App\Models\User::class)->create();
$I->wantTo('Ensure I can delete a user'); $I->wantTo('Ensure I can delete a user');
$I->sendDelete(route('users.destroy', $user->id), ['_token' => csrf_token()]); $I->sendDelete(route('users.destroy', $user->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);

View file

@ -7,4 +7,4 @@ modules:
- \Helper\Unit - \Helper\Unit
- Asserts - Asserts
- Laravel5: - Laravel5:
environment_file: .env.tests environment_file: .env.tests

View file

@ -1,5 +1,6 @@
<?php <?php
use App\Models\Accessory; use App\Models\Accessory;
use App\Models\Category;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
@ -7,23 +8,105 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class AccessoryTest extends \Codeception\TestCase\Test class AccessoryTest extends \Codeception\TestCase\Test
{ {
/** /**
* @var \UnitTester * @var \UnitTester
*/ */
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseTransactions;
public function testAccessoryAdd() protected function _before()
{ {
$accessory = factory(Accessory::class, 'accessory')->make(); Artisan::call('migrate');
$values = [ }
'name' => $accessory->name,
'category_id' => $accessory->category_id,
'qty' => $accessory->qty,
];
Accessory::create($values); public function testAccessoryAdd()
$this->tester->seeRecord('accessories', $values); {
} $accessory = factory(Accessory::class)->make();
$values = [
'name' => $accessory->name,
'category_id' => $accessory->category_id,
'qty' => $accessory->qty,
];
Accessory::create($values);
$this->tester->seeRecord('accessories', $values);
}
public function testFailsEmptyValidation()
{
// An Accessory requires a name, a qty, and a category_id.
$a = Accessory::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 testFailsMinValidation()
{
// An Accessory name has a min length of 3
// An Accessory has a min qty of 1
// An Accessory has a min amount of 0
$a = factory(Accessory::class)->make([
'name' => 'a',
'qty' => 0,
'min_amt' => -1
]);
$fields = [
'name' => 'name',
'qty' => 'qty',
'min_amt' => 'min amt'
];
$this->assertFalse($a->isValid());
$errors = $a->getErrors();
foreach ($fields as $field => $fieldTitle) {
$this->assertContains("The ${fieldTitle} must be at least", $errors->get($field)[0]);
}
}
public function testCategoryIdMustExist()
{
$category = factory(Category::class)->create(['category_type' => 'accessory']);
$accessory = factory(Accessory::class)->make(['category_id' => $category->id]);
$accessory->save();
$this->assertTrue($accessory->isValid());
$newId = $category->id + 1;
$accessory = factory(Accessory::class)->make(['category_id' => $newId]);
$accessory->save();
$this->assertFalse($accessory->isValid());
}
public function testAnAccessoryBelongsToACompany()
{
$accessory = factory(Accessory::class)->create();
$this->assertInstanceOf(App\Models\Company::class, $accessory->company);
}
public function testAnAccessoryHasALocation()
{
$accessory = factory(Accessory::class)->create();
$this->assertInstanceOf(App\Models\Location::class, $accessory->location);
}
public function testAnAccessoryBelongsToACategory()
{
$accessory = factory(Accessory::class)->create();
$this->assertInstanceOf(App\Models\Category::class, $accessory->category);
$this->assertEquals('accessory', $accessory->category->category_type);
}
public function testAnAccessoryHasAManufacturer()
{
$accessory = factory(Accessory::class)->create();
$this->assertInstanceOf(App\Models\Manufacturer::class, $accessory->manufacturer);
}
} }

View file

@ -1,9 +1,10 @@
<?php <?php
use App\Models\Asset;
use App\Models\AssetModel; use App\Models\AssetModel;
use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Hash;
class AssetModelTest extends \Codeception\TestCase\Test class AssetModelTest extends \Codeception\TestCase\Test
{ {
@ -11,26 +12,43 @@ class AssetModelTest extends \Codeception\TestCase\Test
* @var \UnitTester * @var \UnitTester
*/ */
protected $tester; protected $tester;
use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testAssetModelAdd() public function testAssetModelAdd()
{ {
$assetmodel = factory(AssetModel::class, 'assetmodel')->make(); $assetmodel = factory(AssetModel::class)->make();
$values = [ $values = [
'name' => $assetmodel->name, 'name' => $assetmodel->name,
'manufacturer_id' => $assetmodel->manufacturer_id, 'manufacturer_id' => $assetmodel->manufacturer_id,
'category_id' => $assetmodel->category_id, 'category_id' => $assetmodel->category_id,
'eol' => $assetmodel->eol, 'eol' => $assetmodel->eol,
]; ];
AssetModel::create($values); AssetModel::create($values);
$this->tester->seeRecord('models', $values); $this->tester->seeRecord('models', $values);
} }
/** public function testAnAssetModelRequiresAttributes()
* @test {
*/ // An Asset Model requires a name, a category_id, and a manufacturer_id.
public function it_zeros_blank_eol_but_not_others() $a = AssetModel::create();
$this->assertFalse($a->isValid());
$fields = [
'name' => 'name',
'manufacturer_id' => 'manufacturer id',
'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 testAnAssetModelZerosOutBlankEols()
{ {
$am = new AssetModel; $am = new AssetModel;
$am->eol = ''; $am->eol = '';
@ -38,4 +56,31 @@ class AssetModelTest extends \Codeception\TestCase\Test
$am->eol = '4'; $am->eol = '4';
$this->assertTrue($am->eol==4); $this->assertTrue($am->eol==4);
} }
public function testAnAssetModelContainsAssets()
{
$assetmodel = factory(AssetModel::class)->create();
$asset = factory(Asset::class)->create([
'model_id' => $assetmodel->id,
]);
$this->assertEquals(1,$assetmodel->assets()->count());
}
public function testAnAssetModelHasACategory()
{
$assetmodel = factory(AssetModel::class)->create();
$this->assertInstanceOf(App\Models\Category::class, $assetmodel->category);
}
public function anAssetModelHasADepreciation()
{
$assetmodel = factory(AssetModel::class)->create();
$this->assertInstanceOf(App\Models\Depreciation::class, $assetmodel->depreciation);
}
public function testAnAssetModelHasAManufacturer()
{
$assetmodel = factory(AssetModel::class)->create();
$this->assertInstanceOf(App\Models\Manufacturer::class, $assetmodel->manufacturer);
}
} }

View file

@ -1,9 +1,10 @@
<?php <?php
use App\Models\Asset; use App\Models\Asset;
use Illuminate\Support\Facades\Hash; use App\Models\AssetModel;
use Illuminate\Foundation\Testing\WithoutMiddleware; use App\Models\Company;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Hash;
class AssetTest extends \Codeception\TestCase\Test class AssetTest extends \Codeception\TestCase\Test
{ {
@ -11,31 +12,53 @@ class AssetTest extends \Codeception\TestCase\Test
* @var \UnitTester * @var \UnitTester
*/ */
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseTransactions;
protected function _before()
{
Artisan::call('migrate');
}
public function testAssetAdd() public function testAssetAdd()
{ {
$asset = factory(Asset::class, 'asset')->make(); $asset = factory(Asset::class)->make();
$values = [ $values = [
'name' => $asset->name, 'name' => $asset->name,
'model_id' => $asset->model_id, 'model_id' => $asset->model_id,
'status_id' => $asset->status_id, 'status_id' => $asset->status_id,
'asset_tag' => $asset->asset_tag, 'asset_tag' => $asset->asset_tag,
]; ];
Asset::create($values); Asset::create($values);
$this->tester->seeRecord('assets', $values); $this->tester->seeRecord('assets', $values);
} }
public function testFailsEmptyValidation()
{
// An Asset requires a name, a qty, and a category_id.
$a = Asset::create();
$this->assertFalse($a->isValid());
$fields = [
'model_id' => 'model id',
'status_id' => 'status id',
'asset_tag' => 'asset tag'
];
$errors = $a->getErrors();
foreach ($fields as $field => $fieldTitle) {
$this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
}
}
/** /**
* @test * @test
*/ */
public function testWarrantyExpiresAttribute() public function testWarrantyExpiresAttribute()
{ {
$asset = factory(\App\Models\Asset::class, 'asset')->create(); $asset = factory(\App\Models\Asset::class)->create();
$asset->purchase_date = \Carbon\Carbon::createFromDate(2017, 1, 1); $asset->purchase_date = \Carbon\Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0);
$asset->warranty_months = 24; $asset->warranty_months = 24;
$asset->save(); $asset->save();
@ -43,22 +66,192 @@ class AssetTest extends \Codeception\TestCase\Test
$this->tester->assertInstanceOf(\DateTime::class, $saved_asset->purchase_date); $this->tester->assertInstanceOf(\DateTime::class, $saved_asset->purchase_date);
$this->tester->assertEquals( $this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2017,1,1)->format('Y-m-d'), \Carbon\Carbon::createFromDate(2017, 1, 1)->format('Y-m-d'),
$saved_asset->purchase_date->format('Y-m-d') $saved_asset->purchase_date->format('Y-m-d')
); );
$this->tester->assertEquals( $this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2017,1,1)->setTime(0,0,0), \Carbon\Carbon::createFromDate(2017, 1, 1)->setTime(0, 0, 0),
$saved_asset->purchase_date $saved_asset->purchase_date
); );
$this->tester->assertEquals(24, $saved_asset->warranty_months); $this->tester->assertEquals(24, $saved_asset->warranty_months);
$this->tester->assertInstanceOf(\DateTime::class, $saved_asset->warranty_expires); $this->tester->assertInstanceOf(\DateTime::class, $saved_asset->warranty_expires);
$this->tester->assertEquals( $this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2019,1,1)->format('Y-m-d'), \Carbon\Carbon::createFromDate(2019, 1, 1)->format('Y-m-d'),
$saved_asset->warranty_expires->format('Y-m-d') $saved_asset->warranty_expires->format('Y-m-d')
); );
$this->tester->assertEquals( $this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2019,1,1)->setTime(0,0,0), \Carbon\Carbon::createFromDate(2019, 1, 1)->setTime(0, 0, 0),
$saved_asset->warranty_expires $saved_asset->warranty_expires
); );
} }
public function testModelIdMustExist()
{
$model = factory(AssetModel::class)->create();
$asset = factory(Asset::class)->make(['model_id' => $model->id]);
$asset->save();
$this->assertTrue($asset->isValid());
$newId = $model->id + 1;
$asset = factory(Asset::class)->make(['model_id' => $newId]);
$asset->save();
$this->assertFalse($asset->isValid());
}
public function testAnAssetHasRelationships()
{
$asset = factory(Asset::class)->create();
$this->assertInstanceOf(AssetModel::class, $asset->model);
$this->assertInstanceOf(Company::class, $asset->company);
$this->assertInstanceOf(App\Models\Depreciation::class, $asset->depreciation);
$this->assertInstanceOf(App\Models\Statuslabel::class, $asset->assetstatus);
$this->assertInstanceOf(App\Models\Supplier::class, $asset->supplier);
}
public function testAnAssetCanBeAvailableForCheckout()
{
// Logic: If the asset is not assigned to anyone,
// and the statuslabel type is "deployable"
// and the asset is not deleted
// Then it is available for checkout
// An asset assigned to someone should not be available for checkout.
$user = factory(App\Models\User::class)->create();
$assetAssigned = factory(Asset::class)->create(['assigned_to' => $user->id]);
$this->assertFalse($assetAssigned->availableForCheckout());
// An asset with a non deployable statuslabel should not be available for checkout.
$status = factory(App\Models\Statuslabel::class)->states('archived')->create();
$assetUndeployable = factory(Asset::class)->create(['status_id' => $status->id]);
$this->assertFalse($assetUndeployable->availableForCheckout());
// An asset that has been deleted is not avaiable for checkout.
$assetDeleted = factory(Asset::class)->states('deleted')->create();
$this->assertFalse($assetDeleted->availableForCheckout());
// A ready to deploy asset that isn't assigned to anyone is available for checkout
$status = factory(App\Models\Statuslabel::class)->states('rtd')->create();
$asset = factory(Asset::class)->create(['status_id' => $status->id]);
$this->assertTrue($asset->availableForCheckout());
}
public function testAnAssetCanHaveComponents()
{
$asset = factory(Asset::class)->create();
$components = factory(App\Models\Component::class, 5)->create();
$components->each(function($component) use ($asset) {
$component->assets()->attach($component, [
'asset_id'=>$asset->id
]);
});
$this->assertInstanceOf(App\Models\Component::class, $asset->components()->first());
$this->assertCount(5, $asset->components);
}
public function testAnAssetCanHaveUploads()
{
$asset = factory(Asset::class)->create();
$this->assertCount(0, $asset->uploads);
factory(App\Models\Actionlog::class, 'asset-upload')->create(['item_id' => $asset->id]);
$this->assertCount(1, $asset->fresh()->uploads);
}
// Helper Method for checking in assets.... We should extract this to the model or a trait.
private function checkin($asset, $target) {
$asset->expected_checkin = null;
$asset->last_checkout = null;
$asset->assigned_to = null;
$asset->assignedTo()->disassociate($asset);
$asset->accepted = null;
$asset->save();
$asset->logCheckin($target, 'Test Checkin');
}
public function testAnAssetCanBeCheckedOut()
{
// This tests Asset::checkOut(), Asset::assignedTo(), Asset::assignedAssets(), Asset::assetLoc(), Asset::assignedType(), defaultLoc()
// Need to mock settings here to avoid issues with checkout notifications.
factory(App\Models\Setting::class)->create();
$asset = factory(Asset::class)->create();
$adminUser = factory(App\Models\User::class)->states('superuser')->create();
Auth::login($adminUser);
$target = factory(App\Models\User::class)->create();
// An Asset Can be checked out to a user, and this should be logged.
$asset->checkOut($target, $adminUser);
$asset->save();
$this->assertInstanceOf(App\Models\User::class, $asset->assignedTo);
$this->assertEquals($asset->assetLoc->id, $target->userLoc->id);
$this->assertEquals('user', $asset->assignedType());
$this->assertEquals($asset->defaultLoc->id, $asset->rtd_location_id);
$this->tester->seeRecord('action_logs', [
'action_type' => 'checkout',
'target_type' => get_class($target),
'target_id' => $target->id
]);
$this->checkin($asset, $target);
$this->assertNull($asset->fresh()->assignedTo);
$this->tester->seeRecord('action_logs', [
'action_type' => 'checkin from',
'target_type' => get_class($target),
'target_id' => $target->id
]);
// An Asset Can be checked out to a asset, and this should be logged.
$target = factory(App\Models\Asset::class)->create();
$asset->checkOut($target, $adminUser);
$asset->save();
$this->assertInstanceOf(App\Models\Asset::class, $asset->fresh()->assignedTo);
$this->assertEquals($asset->fresh()->assetLoc->id, $target->fresh()->assetLoc->id);
$this->assertEquals('asset', $asset->assignedType());
$this->assertEquals($asset->defaultLoc->id, $asset->rtd_location_id);
$this->tester->seeRecord('action_logs', [
'action_type' => 'checkout',
'target_type' => get_class($target),
'target_id' => $target->id
]);
$this->assertCount(1, $target->assignedAssets);
$this->checkin($asset, $target);
$this->assertNull($asset->fresh()->assignedTo);
$this->tester->seeRecord('action_logs', [
'action_type' => 'checkin from',
'target_type' => get_class($target),
'target_id' => $target->id
]);
// An Asset Can be checked out to a location, and this should be logged.
$target = factory(App\Models\Location::class)->create();
$asset->checkOut($target, $adminUser);
$asset->save();
$this->assertInstanceOf(App\Models\Location::class, $asset->fresh()->assignedTo);
$this->assertEquals($asset->fresh()->assetLoc->id, $target->fresh()->id);
$this->assertEquals('location', $asset->assignedType());
$this->assertEquals($asset->defaultLoc->id, $asset->rtd_location_id);
$this->tester->seeRecord('action_logs', [
'action_type' => 'checkout',
'target_type' => get_class($target),
'target_id' => $target->id
]);
$this->checkin($asset, $target);
$this->assertNull($asset->fresh()->assignedTo);
$this->tester->seeRecord('action_logs', [
'action_type' => 'checkin from',
'target_type' => get_class($target),
'target_id' => $target->id
]);
}
public function testAnAssetHasMaintenances()
{
$asset = factory(Asset::class)->create();
factory(App\Models\AssetMaintenance::class)->create(['asset_id' => $asset->id]);
$this->assertCount(1, $asset->assetmaintenances);
}
} }

View file

@ -13,9 +13,14 @@ class CategoryTest extends \Codeception\TestCase\Test
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testAssetCategoryAdd() public function testAssetCategoryAdd()
{ {
$category = factory(Category::class, 'category')->make(['category_type' => 'asset']); $category = factory(Category::class)->make(['category_type' => 'asset']);
$values = [ $values = [
'name' => $category->name, 'name' => $category->name,
'category_type' => $category->category_type, 'category_type' => $category->category_type,
@ -29,7 +34,7 @@ class CategoryTest extends \Codeception\TestCase\Test
public function testAccessoryCategoryAdd() public function testAccessoryCategoryAdd()
{ {
$category = factory(Category::class, 'category')->make(['category_type' => 'accessory']); $category = factory(Category::class)->make(['category_type' => 'accessory']);
$values = [ $values = [
'name' => $category->name, 'name' => $category->name,
'category_type' => $category->category_type, 'category_type' => $category->category_type,
@ -40,4 +45,57 @@ class CategoryTest extends \Codeception\TestCase\Test
Category::create($values); Category::create($values);
$this->tester->seeRecord('categories', $values); $this->tester->seeRecord('categories', $values);
} }
public function testFailsEmptyValidation()
{
// An Asset requires a name, a qty, and a category_id.
$a = Category::create();
$this->assertFalse($a->isValid());
$fields = [
'name' => 'name',
'category_type' => 'category type'
];
$errors = $a->getErrors();
foreach ($fields as $field => $fieldTitle) {
$this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
}
}
public function testACategoryCanHaveAssets()
{
$category = factory(Category::class)->create(['category_type' => 'asset']);
$models = factory(App\Models\AssetModel::class, 5)->create(['category_id' => $category->id]);
$this->assertEquals(5, $category->has_models());
$this->assertCount(5, $category->models);
$models->each(function($model) {
factory(App\Models\Asset::class, 2)->create(['model_id' => $model->id]);
});
$this->assertEquals(10, $category->itemCount());
}
public function testACategoryCanHaveAccessories()
{
$category = factory(Category::class)->create(['category_type' => 'accessory']);
factory(App\Models\Accessory::class, 5)->create(['category_id' => $category->id]);
$this->assertCount(5, $category->accessories);
$this->assertEquals(5, $category->itemCount());
}
public function testACategoryCanHaveConsumables()
{
$category = factory(Category::class)->create(['category_type' => 'consumable']);
factory(App\Models\Consumable::class, 5)->create(['category_id' => $category->id]);
$this->assertCount(5, $category->consumables);
$this->assertEquals(5, $category->itemCount());
}
public function testACategoryCanHaveComponents()
{
$category = factory(Category::class)->create(['category_type' => 'component']);
factory(App\Models\Component::class, 5)->create(['category_id' => $category->id]);
$this->assertCount(5, $category->components);
$this->assertEquals(5, $category->itemCount());
}
} }

View file

@ -11,17 +11,81 @@ class CompanyTest extends \Codeception\TestCase\Test
* @var \UnitTester * @var \UnitTester
*/ */
protected $tester; protected $tester;
private $company;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
$this->company = factory(Company::class)->create();
}
public function testAssetAdd() public function testAssetAdd()
{ {
$company = factory(Company::class, 'company')->make(); $company = factory(Company::class)->make();
$values = [ $values = [
'name' => $company->name, 'name' => $company->name,
]; ];
Company::create($values); Company::create($values);
$this->tester->seeRecord('companies', $values); $this->tester->seeRecord('companies', $values);
} }
public function testFailsEmptyValidation()
{
// An Company requires a name, a qty, and a category_id.
$a = Company::create();
$this->assertFalse($a->isValid());
$fields = [
'name' => 'name',
];
$errors = $a->getErrors();
foreach ($fields as $field => $fieldTitle) {
$this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
}
}
public function testACompanyCanHaveUsers()
{
$this->company = factory(Company::class)->create();
factory(App\Models\User::class, 1)->create(['company_id'=>$this->company->id]);
$this->assertCount(1, $this->company->users);
}
public function testACompanyCanHaveAssets()
{
$this->company = factory(Company::class)->create();
factory(App\Models\Asset::class, 1)->create(['company_id'=>$this->company->id]);
$this->assertCount(1, $this->company->assets);
}
public function testACompanyCanHaveLicenses()
{
$this->company = factory(Company::class)->create();
factory(App\Models\License::class, 1)->create(['company_id'=>$this->company->id]);
$this->assertCount(1, $this->company->licenses);
}
public function testACompanyCanHaveAccessories()
{
$this->company = factory(Company::class)->create();
factory(App\Models\Accessory::class, 1)->create(['company_id'=>$this->company->id]);
$this->assertCount(1, $this->company->accessories);
}
public function testACompanyCanHaveConsumables()
{
$this->company = factory(Company::class)->create();
factory(App\Models\Consumable::class, 1)->create(['company_id'=>$this->company->id]);
$this->assertCount(1, $this->company->consumables);
}
public function testACompanyCanHaveComponents()
{
$this->company = factory(Company::class)->create();
factory(App\Models\Component::class, 1)->create(['company_id'=>$this->company->id]);
$this->assertCount(1, $this->company->components);
}
} }

View file

@ -13,9 +13,14 @@ class ConsumableTest extends \Codeception\TestCase\Test
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testConsumableAdd() public function testConsumableAdd()
{ {
$consumable = factory(Consumable::class, 'consumable')->make(); $consumable = factory(Consumable::class)->make();
$values = [ $values = [
'name' => $consumable->name, 'name' => $consumable->name,
'qty' => $consumable->qty, 'qty' => $consumable->qty,
@ -27,4 +32,31 @@ class ConsumableTest extends \Codeception\TestCase\Test
$this->tester->seeRecord('consumables', $values); $this->tester->seeRecord('consumables', $values);
} }
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);
}
} }

View file

@ -14,6 +14,11 @@ class CustomFieldTest extends \Codeception\TestCase\Test
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testConstructor() public function testConstructor()
{ {
$customfield = new CustomField(); $customfield = new CustomField();
@ -21,7 +26,7 @@ class CustomFieldTest extends \Codeception\TestCase\Test
public function testFormat() public function testFormat()
{ {
$customfield = factory(CustomField::class, 'customfield-ip')->make(); $customfield = factory(CustomField::class)->make();
$values = [ $values = [
'name' => $customfield->name, 'name' => $customfield->name,
'format' => $customfield->format, 'format' => $customfield->format,

View file

@ -1,9 +1,10 @@
<?php <?php
use App\Models\Department;
use App\Models\Location; use App\Models\Location;
use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Hash;
class DepartmentTest extends \Codeception\TestCase\Test class DepartmentTest extends \Codeception\TestCase\Test
{ {
@ -11,13 +12,20 @@ class DepartmentTest extends \Codeception\TestCase\Test
* @var \UnitTester * @var \UnitTester
*/ */
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseTransactions;
protected function _before()
{
Artisan::call('migrate');
}
public function testDepartmentAdd() public function testDepartmentAdd()
{ {
$department = factory(Department::class, 'department')->make(); $department = factory(Department::class)->make();
$values = [ $values = [
'name' => $department->name, 'name' => $department->name,
'user_id' => $department->user_id,
'manager_id' => $department->manager_id,
]; ];
Department::create($values); Department::create($values);

View file

@ -12,9 +12,14 @@ class DepreciationTest extends \Codeception\TestCase\Test
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testDepreciationAdd() public function testDepreciationAdd()
{ {
$depreciations = factory(Depreciation::class, 'depreciation')->make(); $depreciations = factory(Depreciation::class)->make();
$values = [ $values = [
'name' => $depreciations->name, 'name' => $depreciations->name,
'months' => $depreciations->months, 'months' => $depreciations->months,
@ -24,4 +29,33 @@ class DepreciationTest extends \Codeception\TestCase\Test
$this->tester->seeRecord('depreciations', $values); $this->tester->seeRecord('depreciations', $values);
} }
public function testFailsEmptyValidation()
{
// An Asset requires a name, a qty, and a category_id.
$a = Depreciation::create();
$this->assertFalse($a->isValid());
$fields = [
'name' => 'name',
'months' => 'months',
];
$errors = $a->getErrors();
foreach ($fields as $field => $fieldTitle) {
$this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
}
}
public function testADepreciationHasModels()
{
$depreciation = factory(Depreciation::class)->create();
factory(App\Models\AssetModel::class, 5)->create(['depreciation_id'=>$depreciation->id]);
$this->assertEquals(5,$depreciation->has_models());
}
public function testADepreciationHasLicenses()
{
$depreciation = factory(Depreciation::class)->create();
factory(App\Models\License::class, 5)->create(['depreciation_id'=>$depreciation->id]);
$this->assertEquals(5,$depreciation->has_licenses());
}
} }

View file

@ -8,20 +8,24 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class LocationTest extends \Codeception\TestCase\Test class LocationTest extends \Codeception\TestCase\Test
{ {
/** /**
* @var \UnitTester * @var \UnitTester
*/ */
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
public function testLocationAdd() protected function _before()
{ {
$location = factory(Location::class, 'location')->make(); Artisan::call('migrate');
$values = [
'name' => $location->name,
];
Location::create($values);
$this->tester->seeRecord('locations', $values);
} }
public function testAssetAdd()
{
$location = factory(Location::class)->make();
$values = [
'name' => $location->name,
];
Location::create($values);
$this->tester->seeRecord('locations', $values);
}
} }

View file

@ -13,9 +13,14 @@ class ManufacturerTest extends \Codeception\TestCase\Test
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testManufacturerAdd() public function testManufacturerAdd()
{ {
$manufacturers = factory(Manufacturer::class, 'manufacturer')->make(); $manufacturers = factory(Manufacturer::class)->make();
$values = [ $values = [
'name' => $manufacturers->name, 'name' => $manufacturers->name,
]; ];

View file

@ -10,66 +10,56 @@ use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\WithoutMiddleware;
class PermissionsTest extends TestCase class PermissionsTest extends \Codeception\TestCase\Test
{ {
// use DatabaseMigrations;
use DatabaseTransactions; public function _before()
public function setUp()
{ {
parent::setUp(); Artisan::call('migrate');
$this->hardwareId = Asset::first()->id;
$this->noHardware = [ $this->noHardware = [
route('hardware.index') => 403, 'assets.view' => false,
route('hardware.create') => 403, 'assets.create' => false,
route('hardware.edit', $this->hardwareId) => 403, 'assets.edit' => false,
route('hardware.show', $this->hardwareId) => 403, 'assets.delete' => false,
]; ];
$this->licenseId = License::first()->id;
$this->noLicenses = [ $this->noLicenses = [
route('licenses.index') => 403, 'licenses.view' => false,
route('licenses.create') => 403, 'licenses.create' => false,
route('licenses.edit', $this->licenseId) => 403, 'licenses.edit' => false,
route('licenses.show', $this->licenseId) => 403, 'licenses.delete' => false,
]; ];
$this->accessoryId = Accessory::first()->id;
$this->noAccessories = [ $this->noAccessories = [
route('accessories.index') => 403, 'accessories.view' => false,
route('accessories.create') => 403, 'accessories.create' => false,
route('accessories.edit', $this->accessoryId) => 403, 'accessories.edit' => false,
route('accessories.show', $this->accessoryId) => 403, 'accessories.delete' => false,
]; ];
$this->consumableId = Consumable::first()->id;
$this->noConsumables = [ $this->noConsumables = [
route('consumables.index') => 403, 'consumables.view' => false,
route('consumables.create') => 403, 'consumables.create' => false,
route('consumables.edit', $this->consumableId) => 403, 'consumables.edit' => false,
route('consumables.show', $this->consumableId) => 403, 'consumables.delete' => false,
]; ];
$this->componentId = Component::first()->id;
$this->noComponents = [ $this->noComponents = [
route('components.index') => 403, 'components.view' => false,
route('components.create') => 403, 'components.create' => false,
route('components.edit', $this->componentId) => 403, 'components.edit' => false,
route('components.show', $this->componentId) => 403, 'components.delete' => false,
]; ];
$this->userId = User::first()->id;
$this->noUsers = [ $this->noUsers = [
route('users.index') => 403, 'users.view' => false,
route('users.create') => 403, 'users.create' => false,
route('users.edit', $this->userId) => 403, 'users.edit' => false,
route('users.show', $this->userId) => 403, 'users.delete' => false,
]; ];
} }
public function tearDown()
{
}
private $noHardware; private $noHardware;
private $noLicenses; private $noLicenses;
private $noAccessories; private $noAccessories;
@ -77,24 +67,16 @@ class PermissionsTest extends TestCase
private $noComponents; private $noComponents;
private $noUsers; private $noUsers;
// An existing id for each type;
private $hardwareId;
private $licenseId;
private $accessoryId;
private $consumableId;
private $componentId;
private $userId;
// tests // tests
/** /**
* @test * @test
*/ */
public function a_user_with_no_permissions_sees_nothing() public function a_user_with_no_permissions_sees_nothing()
{ {
$u = factory(App\Models\User::class, 'valid-user')->create(); $u = factory(App\Models\User::class)->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = $this->noHardware; // $permissions = $this->noHardware;
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
/** /**
@ -102,14 +84,14 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_view_asset_permissions_can_view_assets() public function a_user_with_view_asset_permissions_can_view_assets()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('view-assets')->create(); $u = factory(App\Models\User::class)->states('view-assets')->create();
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('hardware.index') => 200, 'assets.view' => true,
route('hardware.create') => 403, 'assets.create' => false,
route('hardware.edit', $this->hardwareId) => 403, 'assets.edit' => false,
route('hardware.show', $this->hardwareId) => 200, 'assets.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -119,14 +101,14 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_create_asset_permissions_can_create_assets() public function a_user_with_create_asset_permissions_can_create_assets()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('create-assets')->create(); $u = factory(App\Models\User::class)->states('create-assets')->create();
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('hardware.index') => 403, 'assets.view' => false,
route('hardware.create') => 200, 'assets.create' => true,
route('hardware.edit', $this->hardwareId) => 403, 'assets.edit' => false,
route('hardware.show', $this->hardwareId) => 403, 'assets.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -136,15 +118,31 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_edit_assets_permissions_can_edit_assets() public function a_user_with_edit_assets_permissions_can_edit_assets()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('edit-assets')->create(); $u = factory(App\Models\User::class)->states('edit-assets')->create();
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('hardware.index') => 403, 'assets.view' => false,
route('hardware.create') => 403, 'assets.create' => false,
route('hardware.edit', $this->hardwareId) => 200, 'assets.edit' => true,
route('hardware.show', $this->hardwareId) => 403, 'assets.delete' => false,
]);
$this->hitRoutes($permissions, $u);
}
/**
* @test
*/
public function a_user_with_delete_assets_permissions_can_delete_assets()
{
$u = factory(App\Models\User::class)->states('delete-assets')->create();
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [
'assets.view' => false,
'assets.create' => false,
'assets.edit' => false,
'assets.delete' => true,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -154,14 +152,14 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_view_licenses_permissions_can_view_licenses() public function a_user_with_view_licenses_permissions_can_view_licenses()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('view-licenses')->create(); $u = factory(App\Models\User::class)->states('view-licenses')->create();
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('licenses.index') => 200, 'licenses.view' => true,
route('licenses.create') => 403, 'licenses.create' => false,
route('licenses.edit', $this->licenseId) => 403, 'licenses.edit' => false,
route('licenses.show', $this->licenseId) => 200, 'licenses.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -171,14 +169,14 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_create_licenses_permissions_can_create_licenses() public function a_user_with_create_licenses_permissions_can_create_licenses()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('create-licenses')->create(); $u = factory(App\Models\User::class)->states('create-licenses')->create();
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('licenses.index') => 403, 'licenses.view' => false,
route('licenses.create') => 200, 'licenses.create' => true,
route('licenses.edit', $this->licenseId) => 403, 'licenses.edit' => false,
route('licenses.show', $this->licenseId) => 403, 'licenses.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -188,14 +186,31 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_edit_licenses_permissions_can_edit_licenses() public function a_user_with_edit_licenses_permissions_can_edit_licenses()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('edit-licenses')->create(); $u = factory(App\Models\User::class)->states('edit-licenses')->create();
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('licenses.index') => 403, 'licenses.view' => false,
route('licenses.create') => 403, 'licenses.create' => false,
route('licenses.edit', $this->licenseId) => 200, 'licenses.edit' => true,
route('licenses.show', $this->licenseId) => 403, 'licenses.delete' => false,
]);
$this->hitRoutes($permissions, $u);
}
/**
* @test
*/
public function a_user_with_delete_licenses_permissions_can_delete_licenses()
{
$u = factory(App\Models\User::class)->states('delete-licenses')->create();
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [
'licenses.view' => false,
'licenses.create' => false,
'licenses.edit' => false,
'licenses.delete' => true,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -205,15 +220,15 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_view_accessories_permissions_can_view_accessories() public function a_user_with_view_accessories_permissions_can_view_accessories()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('view-accessories')->create(); $u = factory(App\Models\User::class)->states('view-accessories')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('accessories.index') => 200, 'accessories.view' => true,
route('accessories.create') => 403, 'accessories.create' => false,
route('accessories.edit', $this->accessoryId) => 403, 'accessories.edit' => false,
route('accessories.show', $this->accessoryId) => 200, 'accessories.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -223,15 +238,15 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_create_accessories_permissions_can_create_accessories() public function a_user_with_create_accessories_permissions_can_create_accessories()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('create-accessories')->create(); $u = factory(App\Models\User::class)->states('create-accessories')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('accessories.index') => 403, 'accessories.view' => false,
route('accessories.create') => 200, 'accessories.create' => true,
route('accessories.edit', $this->accessoryId) => 403, 'accessories.edit' => false,
route('accessories.show', $this->accessoryId) => 403, 'accessories.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -241,15 +256,33 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_edit_accessories_permissions_can_edit_accessories() public function a_user_with_edit_accessories_permissions_can_edit_accessories()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('edit-accessories')->create(); $u = factory(App\Models\User::class)->states('edit-accessories')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('accessories.index') => 403, 'accessories.view' => false,
route('accessories.create') => 403, 'accessories.create' => false,
route('accessories.edit', $this->accessoryId) => 200, 'accessories.edit' => true,
route('accessories.show', $this->accessoryId) => 403, 'accessories.delete' => false,
]);
$this->hitRoutes($permissions, $u);
}
/**
* @test
*/
public function a_user_with_delete_accessories_permissions_can_delete_accessories()
{
$u = factory(App\Models\User::class)->states('delete-accessories')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [
'accessories.view' => false,
'accessories.create' => false,
'accessories.edit' => false,
'accessories.delete' => true,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -259,15 +292,15 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_view_consumables_permissions_can_view_consumables() public function a_user_with_view_consumables_permissions_can_view_consumables()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('view-consumables')->create(); $u = factory(App\Models\User::class)->states('view-consumables')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('consumables.index') => 200, 'consumables.view' => true,
route('consumables.create') => 403, 'consumables.create' => false,
route('consumables.edit', $this->consumableId) => 403, 'consumables.edit' => false,
route('consumables.show', $this->consumableId) => 200, 'consumables.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -277,15 +310,15 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_create_consumables_permissions_can_create_consumables() public function a_user_with_create_consumables_permissions_can_create_consumables()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('create-consumables')->create(); $u = factory(App\Models\User::class)->states('create-consumables')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('consumables.index') => 403, 'consumables.view' => false,
route('consumables.create') => 200, 'consumables.create' => true,
route('consumables.edit', $this->consumableId) => 403, 'consumables.edit' => false,
route('consumables.show', $this->consumableId) => 403, 'consumables.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -295,15 +328,33 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_edit_consumables_permissions_can_edit_consumables() public function a_user_with_edit_consumables_permissions_can_edit_consumables()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('edit-consumables')->create(); $u = factory(App\Models\User::class)->states('edit-consumables')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('consumables.index') => 403, 'consumables.view' => false,
route('consumables.create') => 403, 'consumables.create' => false,
route('consumables.edit', $this->consumableId) => 200, 'consumables.edit' => true,
route('consumables.show', $this->consumableId) => 403, 'consumables.delete' => false,
]);
$this->hitRoutes($permissions, $u);
}
/**
* @test
*/
public function a_user_with_delete_consumables_permissions_can_delete_consumables()
{
$u = factory(App\Models\User::class)->states('delete-consumables')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
$permissions = array_merge($permissions, [
'consumables.view' => false,
'consumables.create' => false,
'consumables.edit' => false,
'consumables.delete' => true,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -313,15 +364,15 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_view_users_permissions_can_view_users() public function a_user_with_view_users_permissions_can_view_users()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('view-users')->create(); $u = factory(App\Models\User::class)->states('view-users')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('users.index') => 200, 'users.view' => true,
route('users.create') => 403, 'users.create' => false,
route('users.edit', $this->userId) => 403, 'users.edit' => false,
route('users.show', $this->userId) => 200, 'users.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -331,15 +382,15 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_create_users_permissions_can_create_users() public function a_user_with_create_users_permissions_can_create_users()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('create-users')->create(); $u = factory(App\Models\User::class)->states('create-users')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('users.index') => 403, 'users.view' => false,
route('users.create') => 200, 'users.create' => true,
route('users.edit', $this->userId) => 403, 'users.edit' => false,
route('users.show', $this->userId) => 403, 'users.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -349,15 +400,33 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_edit_users_permissions_can_edit_users() public function a_user_with_edit_users_permissions_can_edit_users()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('edit-users')->create(); $u = factory(App\Models\User::class)->states('edit-users')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('users.index') => 403, 'users.view' => false,
route('users.create') => 403, 'users.create' => false,
route('users.edit', $this->userId) => 200, 'users.edit' => true,
route('users.show', $this->userId) => 403, 'users.delete' => false,
]);
$this->hitRoutes($permissions, $u);
}
/**
* @test
*/
public function a_user_with_delete_users_permissions_can_delete_users()
{
$u = factory(App\Models\User::class)->states('delete-users')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents;
$permissions = array_merge($permissions, [
'users.view' => false,
'users.create' => false,
'users.edit' => false,
'users.delete' => true,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -367,15 +436,15 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_view_components_permissions_can_view_components() public function a_user_with_view_components_permissions_can_view_components()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('view-components')->create(); $u = factory(App\Models\User::class)->states('view-components')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('components.index') => 200, 'components.view' => true,
route('components.create') => 403, 'components.create' => false,
route('components.edit', $this->componentId) => 403, 'components.edit' => false,
route('components.show', $this->componentId) => 200, 'components.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -385,14 +454,14 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_create_components_permissions_can_create_components() public function a_user_with_create_components_permissions_can_create_components()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('create-components')->create(); $u = factory(App\Models\User::class)->states('create-components')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('components.index') => 403, 'components.view' => false,
route('components.create') => 200, 'components.create' => true,
route('components.edit', $this->componentId) => 403, 'components.edit' => false,
route('components.show', $this->componentId) => 403, 'components.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
@ -402,26 +471,42 @@ class PermissionsTest extends TestCase
*/ */
public function a_user_with_edit_components_permissions_can_edit_components() public function a_user_with_edit_components_permissions_can_edit_components()
{ {
$u = factory(App\Models\User::class, 'valid-user')->states('edit-components')->create(); $u = factory(App\Models\User::class)->states('edit-components')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers; $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers;
$permissions = array_merge($permissions, [ $permissions = array_merge($permissions, [
route('components.index') => 403, 'components.view' => false,
route('components.create') => 403, 'components.create' => false,
route('components.edit', $this->componentId) => 200, 'components.edit' => true,
route('components.show', $this->componentId) => 403, 'components.delete' => false,
]); ]);
$this->hitRoutes($permissions, $u); $this->hitRoutes($permissions, $u);
} }
/**
* @test
*/
public function a_user_with_delete_components_permissions_can_delete_components()
{
$u = factory(App\Models\User::class)->states('delete-components')->create();
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers;
$permissions = array_merge($permissions, [
'components.view' => false,
'components.create' => false,
'components.edit' => false,
'components.delete' => true,
]);
// dd($u);
$this->hitRoutes($permissions, $u);
}
private function hitRoutes(array $routes, User $user) private function hitRoutes(array $routes, User $user)
{ {
$this->actingAs($user); foreach ($routes as $route => $expectation) {
$this->assertEquals($user->hasAccess($route), $expectation);
foreach ($routes as $route => $response) {
$this->get($route)
->assertStatus($response);
} }
} }
} }

View file

@ -14,6 +14,11 @@ class SnipeModelTest extends \Codeception\TestCase\Test
/** /**
* @test * @test
*/ */
protected function _before()
{
Artisan::call('migrate');
}
public function it_sets_purchase_dates_appropriately() public function it_sets_purchase_dates_appropriately()
{ {
$c = new SnipeModel; $c = new SnipeModel;

View file

@ -8,112 +8,112 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class StatuslabelTest extends \Codeception\TestCase\Test class StatuslabelTest extends \Codeception\TestCase\Test
{ {
/** /**
* @var \UnitTester * @var \UnitTester
*/ */
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testRTDStatuslabelAdd() public function testRTDStatuslabelAdd()
{ {
$statuslabel = factory(Statuslabel::class, 'rtd')->make(); $statuslabel = factory(Statuslabel::class)->states('rtd')->make();
$values = [ $values = [
'name' => $statuslabel->name, 'name' => $statuslabel->name,
'deployable' => $statuslabel->deployable, 'deployable' => $statuslabel->deployable,
'pending' => $statuslabel->pending, 'pending' => $statuslabel->pending,
'archived' => $statuslabel->archived, 'archived' => $statuslabel->archived,
]; ];
Statuslabel::create($values); Statuslabel::create($values);
$this->tester->seeRecord('status_labels', $values); $this->tester->seeRecord('status_labels', $values);
} }
public function testPendingStatuslabelAdd() public function testPendingStatuslabelAdd()
{ {
$statuslabel = factory(Statuslabel::class, 'pending')->make(); $statuslabel = factory(Statuslabel::class)->states('pending')->make();
$values = [ $values = [
'name' => $statuslabel->name, 'name' => $statuslabel->name,
'deployable' => $statuslabel->deployable, 'deployable' => $statuslabel->deployable,
'pending' => $statuslabel->pending, 'pending' => $statuslabel->pending,
'archived' => $statuslabel->archived, 'archived' => $statuslabel->archived,
]; ];
Statuslabel::create($values); Statuslabel::create($values);
$this->tester->seeRecord('status_labels', $values); $this->tester->seeRecord('status_labels', $values);
} }
public function testArchivedStatuslabelAdd() public function testArchivedStatuslabelAdd()
{ {
$statuslabel = factory(Statuslabel::class, 'archived')->make(); $statuslabel = factory(Statuslabel::class)->states('archived')->make();
$values = [ $values = [
'name' => $statuslabel->name, 'name' => $statuslabel->name,
'deployable' => $statuslabel->deployable, 'deployable' => $statuslabel->deployable,
'pending' => $statuslabel->pending, 'pending' => $statuslabel->pending,
'archived' => $statuslabel->archived, 'archived' => $statuslabel->archived,
]; ];
Statuslabel::create($values); Statuslabel::create($values);
$this->tester->seeRecord('status_labels', $values); $this->tester->seeRecord('status_labels', $values);
} }
public function testOutForRepairStatuslabelAdd() public function testOutForRepairStatuslabelAdd()
{ {
$statuslabel = factory(Statuslabel::class, 'out_for_repair')->make(); $statuslabel = factory(Statuslabel::class)->states('out_for_repair')->make();
$values = [ $values = [
'name' => $statuslabel->name, 'name' => $statuslabel->name,
'deployable' => $statuslabel->deployable, 'deployable' => $statuslabel->deployable,
'pending' => $statuslabel->pending, 'pending' => $statuslabel->pending,
'archived' => $statuslabel->archived, 'archived' => $statuslabel->archived,
]; ];
Statuslabel::create($values); Statuslabel::create($values);
$this->tester->seeRecord('status_labels', $values); $this->tester->seeRecord('status_labels', $values);
} }
public function testOutForDiagnosticsStatuslabelAdd() public function testOutForDiagnosticsStatuslabelAdd()
{ {
$statuslabel = factory(Statuslabel::class, 'out_for_diagnostics')->make(); $statuslabel = factory(Statuslabel::class)->states('out_for_diagnostics')->make();
$values = [ $values = [
'name' => $statuslabel->name, 'name' => $statuslabel->name,
'deployable' => $statuslabel->deployable, 'deployable' => $statuslabel->deployable,
'pending' => $statuslabel->pending, 'pending' => $statuslabel->pending,
'archived' => $statuslabel->archived, 'archived' => $statuslabel->archived,
]; ];
Statuslabel::create($values); Statuslabel::create($values);
$this->tester->seeRecord('status_labels', $values); $this->tester->seeRecord('status_labels', $values);
} }
public function testBrokenStatuslabelAdd() public function testBrokenStatuslabelAdd()
{ {
$statuslabel = factory(Statuslabel::class, 'broken')->make(); $statuslabel = factory(Statuslabel::class)->states('broken')->make();
$values = [ $values = [
'name' => $statuslabel->name, 'name' => $statuslabel->name,
'deployable' => $statuslabel->deployable, 'deployable' => $statuslabel->deployable,
'pending' => $statuslabel->pending, 'pending' => $statuslabel->pending,
'archived' => $statuslabel->archived, 'archived' => $statuslabel->archived,
]; ];
Statuslabel::create($values); Statuslabel::create($values);
$this->tester->seeRecord('status_labels', $values); $this->tester->seeRecord('status_labels', $values);
} }
public function testLostStatuslabelAdd() public function testLostStatuslabelAdd()
{ {
$statuslabel = factory(Statuslabel::class, 'lost')->make(); $statuslabel = factory(Statuslabel::class)->states('lost')->make();
$values = [ $values = [
'name' => $statuslabel->name, 'name' => $statuslabel->name,
'deployable' => $statuslabel->deployable, 'deployable' => $statuslabel->deployable,
'pending' => $statuslabel->pending, 'pending' => $statuslabel->pending,
'archived' => $statuslabel->archived, 'archived' => $statuslabel->archived,
]; ];
Statuslabel::create($values); Statuslabel::create($values);
$this->tester->seeRecord('status_labels', $values); $this->tester->seeRecord('status_labels', $values);
} }
} }

View file

@ -13,9 +13,14 @@ class SupplierTest extends \Codeception\TestCase\Test
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testSupplierAdd() public function testSupplierAdd()
{ {
$supplier = factory(Supplier::class, 'supplier')->make(); $supplier = factory(Supplier::class)->make();
$values = [ $values = [
'name' => $supplier->name, 'name' => $supplier->name,
]; ];

View file

@ -13,9 +13,14 @@ class UserTest extends \Codeception\TestCase\Test
protected $tester; protected $tester;
use DatabaseMigrations; use DatabaseMigrations;
protected function _before()
{
Artisan::call('migrate');
}
public function testUserAdd() public function testUserAdd()
{ {
$user = factory(User::class, 'valid-user')->make(); $user = factory(User::class)->make();
$values = [ $values = [
'first_name' => $user->first_name, 'first_name' => $user->first_name,
'last_name' => $user->last_name, 'last_name' => $user->last_name,