From ae0573b3dafc015e4b5fd48cbc5e38e4cb45c352 Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Wed, 6 Sep 2017 19:24:43 -0400 Subject: [PATCH] Fix asset create (#3929) * Fix accidental commit of ImporterTest. * Move the name() method to the presenter This fixes some weird collisions between laravels voodoo and our presenter voodoo that confused php. It's also probably a cleaner place to put it. Should fix #3927 * Add missing parenthesis * Add heading to tables on locations/view page. --- app/Models/SnipeModel.php | 4 - app/Presenters/Presenter.php | 5 + resources/views/categories/view.blade.php | 2 +- resources/views/locations/view.blade.php | 10 + tests/unit/ImporterTest.php | 298 +++++++++++----------- 5 files changed, 164 insertions(+), 155 deletions(-) diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php index 8e2509ed06..43cf0cfc92 100644 --- a/app/Models/SnipeModel.php +++ b/app/Models/SnipeModel.php @@ -82,8 +82,4 @@ class SnipeModel extends Model { return $this->name; } - - public function name() { - return $this->name; - } } diff --git a/app/Presenters/Presenter.php b/app/Presenters/Presenter.php index 821553e022..c47c2547d9 100644 --- a/app/Presenters/Presenter.php +++ b/app/Presenters/Presenter.php @@ -65,6 +65,11 @@ abstract class Presenter return ''; } + public function name() + { + return $this->model->name; + } + public function __get($property) { if (method_exists($this, $property)) { diff --git a/resources/views/categories/view.blade.php b/resources/views/categories/view.blade.php index 0e2dbdb5df..9763b0ab8e 100644 --- a/resources/views/categories/view.blade.php +++ b/resources/views/categories/view.blade.php @@ -32,7 +32,7 @@ name="category_assets" class="snipe-table" id="table" - data-url="{{ route('api.'.$category_type_route.'.index',['category_id'=> $category->id]) }} + data-url="{{ route('api.'.$category_type_route.'.index',['category_id'=> $category->id]) }}" data-cookie="true" data-click-to-select="true" data-cookie-id-table="category{{ $category_type_route }}Table"> diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index ce8c4ac96e..4628a58ca4 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -21,6 +21,11 @@
+
+
+

{{ trans('general.users') }}

+
+
@@ -50,6 +55,11 @@
+
+
+

{{ trans('general.assets') }}

+
+
diff --git a/tests/unit/ImporterTest.php b/tests/unit/ImporterTest.php index ef5e65f233..a90963211d 100644 --- a/tests/unit/ImporterTest.php +++ b/tests/unit/ImporterTest.php @@ -18,181 +18,181 @@ class ImporterTest extends BaseTest */ protected $tester; -// public function testDefaultImportAsset() -// { -// $csv = <<<'EOT' -// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan -// EOT; -// $this->import(new AssetImporter($csv)); -// // Did we create a user? + public function testDefaultImportAsset() + { + $csv = <<<'EOT' +Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier +Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan +EOT; + $this->import(new AssetImporter($csv)); + // Did we create a user? -// $this->tester->seeRecord('users', [ -// 'first_name' => 'Bonnie', -// 'last_name' => 'Nelson', -// 'email' => 'bnelson0@cdbaby.com', -// ]); -// $this->tester->seeRecord('categories', [ -// 'name' => 'quam' -// ]); + $this->tester->seeRecord('users', [ + 'first_name' => 'Bonnie', + 'last_name' => 'Nelson', + 'email' => 'bnelson0@cdbaby.com', + ]); + $this->tester->seeRecord('categories', [ + 'name' => 'quam' + ]); -// $this->tester->seeRecord('models', [ -// 'name' => 'massa id', -// 'model_number' => 6377018600094472 -// ]); + $this->tester->seeRecord('models', [ + 'name' => 'massa id', + 'model_number' => 6377018600094472 + ]); -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Linkbridge' -// ]); + $this->tester->seeRecord('manufacturers', [ + 'name' => 'Linkbridge' + ]); -// $this->tester->seeRecord('locations', [ -// 'name' => 'Daping' -// ]); + $this->tester->seeRecord('locations', [ + 'name' => 'Daping' + ]); -// $this->tester->seeRecord('companies', [ -// 'name' => 'Alpha' -// ]); + $this->tester->seeRecord('companies', [ + 'name' => 'Alpha' + ]); -// $this->tester->seeRecord('status_labels', [ -// 'name' => 'Undeployable' -// ]); + $this->tester->seeRecord('status_labels', [ + 'name' => 'Undeployable' + ]); -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Blogspan' -// ]); -// $this->tester->seeRecord('assets', [ -// 'name' => 'eget nunc donec quis', -// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', -// 'asset_tag' => '970882174-8', -// 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.", -// 'purchase_date' => '2016-04-05 00:00:01', -// 'purchase_cost' => 133289.59, -// 'warranty_months' => 14 -// ]); -// } + $this->tester->seeRecord('suppliers', [ + 'name' => 'Blogspan' + ]); + $this->tester->seeRecord('assets', [ + 'name' => 'eget nunc donec quis', + 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', + 'asset_tag' => '970882174-8', + 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.", + 'purchase_date' => '2016-04-05 00:00:01', + 'purchase_cost' => 133289.59, + 'warranty_months' => 14 + ]); + } -// public function testUpdateAsset() -// { -// $csv = <<<'EOT' -// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan -// EOT; -// $this->import(new AssetImporter($csv)); -// $updatedCSV = <<<'EOT' -// item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier -// A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative -// EOT; -// $importer = new AssetImporter($updatedCSV); -// $importer->setUserId(1) -// ->setUpdating(true) -// ->setUsernameFormat('firstname.lastname') -// ->import(); + public function testUpdateAsset() + { + $csv = <<<'EOT' +Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier +Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan +EOT; + $this->import(new AssetImporter($csv)); + $updatedCSV = <<<'EOT' +item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier +A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative +EOT; + $importer = new AssetImporter($updatedCSV); + $importer->setUserId(1) + ->setUpdating(true) + ->setUsernameFormat('firstname.lastname') + ->import(); -// $this->tester->seeRecord('categories', [ -// 'name' => 'some other category' -// ]); + $this->tester->seeRecord('categories', [ + 'name' => 'some other category' + ]); -// $this->tester->seeRecord('models', [ -// 'name' => 'Another Model', -// 'model_number' => 356 -// ]); + $this->tester->seeRecord('models', [ + 'name' => 'Another Model', + 'model_number' => 356 + ]); -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Linkbridge 32' -// ]); + $this->tester->seeRecord('manufacturers', [ + 'name' => 'Linkbridge 32' + ]); -// $this->tester->seeRecord('locations', [ -// 'name' => 'New Location' -// ]); + $this->tester->seeRecord('locations', [ + 'name' => 'New Location' + ]); -// $this->tester->seeRecord('companies', [ -// 'name' => 'Another Company' -// ]); + $this->tester->seeRecord('companies', [ + 'name' => 'Another Company' + ]); -// $this->tester->seeRecord('status_labels', [ -// 'name' => 'Ready To Go' -// ]); + $this->tester->seeRecord('status_labels', [ + 'name' => 'Ready To Go' + ]); -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Not Creative' -// ]); + $this->tester->seeRecord('suppliers', [ + 'name' => 'Not Creative' + ]); -// $this->tester->seeRecord('assets', [ -// 'name' => 'A new name', -// 'serial' => '67433477', -// 'asset_tag' => '970882174-8', -// 'notes' => "I have no notes", -// 'purchase_date' => '2018-04-05 00:00:01', -// 'purchase_cost' => 25.59, -// 'warranty_months' => 18 -// ]); -// } + $this->tester->seeRecord('assets', [ + 'name' => 'A new name', + 'serial' => '67433477', + 'asset_tag' => '970882174-8', + 'notes' => "I have no notes", + 'purchase_date' => '2018-04-05 00:00:01', + 'purchase_cost' => 25.59, + 'warranty_months' => 18 + ]); + } -// public function testCustomMappingImport() -// { -// $csv = <<<'EOT' -// Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial number,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan -// EOT; + public function testCustomMappingImport() + { + $csv = <<<'EOT' +Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial number,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier +Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan +EOT; -// $customFieldMap = [ -// 'asset_tag' => 'Asset', -// 'category' => 'Cat', -// 'company' => 'comp', -// 'item_name' => 'object name', -// 'expiration_date' => 'expiration date', -// 'location' => 'loc', -// 'notes' => 'Some Notes', -// 'asset_model' => "model name", -// ]; + $customFieldMap = [ + 'asset_tag' => 'Asset', + 'category' => 'Cat', + 'company' => 'comp', + 'item_name' => 'object name', + 'expiration_date' => 'expiration date', + 'location' => 'loc', + 'notes' => 'Some Notes', + 'asset_model' => "model name", + ]; -// $this->import(new AssetImporter($csv), $customFieldMap); -// // Did we create a user? + $this->import(new AssetImporter($csv), $customFieldMap); + // Did we create a user? -// $this->tester->seeRecord('users', [ -// 'first_name' => 'Bonnie', -// 'last_name' => 'Nelson', -// 'email' => 'bnelson0@cdbaby.com', -// ]); + $this->tester->seeRecord('users', [ + 'first_name' => 'Bonnie', + 'last_name' => 'Nelson', + 'email' => 'bnelson0@cdbaby.com', + ]); -// $this->tester->seeRecord('categories', [ -// 'name' => 'quam' -// ]); + $this->tester->seeRecord('categories', [ + 'name' => 'quam' + ]); -// $this->tester->seeRecord('models', [ -// 'name' => 'massa id', -// 'model_number' => 6377018600094472 -// ]); + $this->tester->seeRecord('models', [ + 'name' => 'massa id', + 'model_number' => 6377018600094472 + ]); -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Linkbridge' -// ]); + $this->tester->seeRecord('manufacturers', [ + 'name' => 'Linkbridge' + ]); -// $this->tester->seeRecord('locations', [ -// 'name' => 'Daping' -// ]); + $this->tester->seeRecord('locations', [ + 'name' => 'Daping' + ]); -// $this->tester->seeRecord('companies', [ -// 'name' => 'Alpha' -// ]); + $this->tester->seeRecord('companies', [ + 'name' => 'Alpha' + ]); -// $this->tester->seeRecord('status_labels', [ -// 'name' => 'Undeployable' -// ]); + $this->tester->seeRecord('status_labels', [ + 'name' => 'Undeployable' + ]); -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Blogspan' -// ]); -// $this->tester->seeRecord('assets', [ -// 'name' => 'eget nunc donec quis', -// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', -// 'asset_tag' => '970882174-8', -// 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.", -// 'purchase_date' => '2016-04-05 00:00:01', -// 'purchase_cost' => 133289.59, -// 'warranty_months' => 14 -// ]); -// } + $this->tester->seeRecord('suppliers', [ + 'name' => 'Blogspan' + ]); + $this->tester->seeRecord('assets', [ + 'name' => 'eget nunc donec quis', + 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', + 'asset_tag' => '970882174-8', + 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.", + 'purchase_date' => '2016-04-05 00:00:01', + 'purchase_cost' => 133289.59, + 'warranty_months' => 14 + ]); + } public function testDefaultAccessoryImport() { @@ -546,8 +546,6 @@ EOT; if ($mappings) { $importer->setFieldMappings($mappings); } - dd($this); - $importer->setUserId(1) ->setUpdating(false) ->setUsernameFormat('firstname.lastname')