2017-07-11 20:37:02 -07:00
< ? php
use App\Importer\AccessoryImporter ;
use App\Importer\AssetImporter ;
use App\Importer\ConsumableImporter ;
2017-09-18 12:29:08 -07:00
use App\Importer\LicenseImporter ;
2018-07-18 19:15:07 -07:00
use App\Importer\UserImporter ;
2017-07-11 20:37:02 -07:00
use App\Models\Accessory ;
2017-09-18 12:29:08 -07:00
use App\Models\Asset ;
2017-07-11 20:37:02 -07:00
use App\Models\AssetModel ;
use App\Models\Category ;
2017-09-18 12:29:08 -07:00
use App\Models\CustomField ;
2018-07-05 12:22:24 -07:00
use App\Models\Location ;
2017-09-18 16:40:13 -07:00
use App\Models\User ;
2017-07-11 20:37:02 -07:00
use Illuminate\Foundation\Testing\DatabaseMigrations ;
use Illuminate\Foundation\Testing\DatabaseTransactions ;
use Illuminate\Foundation\Testing\WithoutMiddleware ;
use Illuminate\Support\Facades\Hash ;
2018-07-18 19:15:07 -07:00
use Illuminate\Support\Facades\Notification ;
2017-07-11 20:37:02 -07:00
class ImporterTest extends BaseTest
{
/**
* @ var \UnitTester
*/
protected $tester ;
2017-09-18 12:29:08 -07:00
public function testDefaultImportAssetWithCustomFields ()
2017-09-06 16:24:43 -07:00
{
2018-01-25 10:10:56 -08:00
$this -> signIn ();
2017-09-06 16:24:43 -07:00
$csv = <<< 'EOT'
2018-02-21 16:42:36 -08:00
Full Name , Email , Username , item Name , Category , Model name , Manufacturer , Model Number , Serial , Asset Tag , Location , Notes , Purchase Date , Purchase Cost , Company , Status , Warranty , Supplier , Weight
2017-09-18 12:29:08 -07:00
Bonnie Nelson , bnelson0 @ cdbaby . com , bnelson0 , eget nunc donec quis , quam , massa id , Linkbridge , 6377018600094472 , 27 aa8378 - b0f4 - 4289 - 84 a4 - 405 da95c6147 , 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 , 35
2017-09-06 16:24:43 -07:00
EOT ;
2017-09-18 12:29:08 -07:00
$this -> initializeCustomFields ();
2017-09-06 16:24:43 -07:00
$this -> import ( new AssetImporter ( $csv ));
$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 ( 'manufacturers' , [
'name' => 'Linkbridge'
]);
$this -> tester -> seeRecord ( 'locations' , [
'name' => 'Daping'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Alpha'
]);
$this -> tester -> seeRecord ( 'status_labels' , [
'name' => 'Undeployable'
]);
$this -> tester -> seeRecord ( 'suppliers' , [
'name' => 'Blogspan'
]);
2017-11-24 10:42:11 -08:00
2017-09-06 16:24:43 -07:00
$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' ,
2018-07-05 12:22:24 -07:00
'purchase_cost' => 133289.59
, 'warranty_months' => 14 ,
2017-09-18 12:29:08 -07:00
'_snipeit_weight_2' => 35
2017-09-06 16:24:43 -07:00
]);
}
2018-07-05 12:22:24 -07:00
public function testImportCheckoutToLocation ()
{
$this -> signIn ();
// Testing in order:
// * Asset to user, no checkout type defined (default to user).
// * Asset to user, explicit user checkout type (Checkout to user)
// * Asset to location, location does not exist to begin with
// * Asset to preexisting location.
$csv = <<< 'EOT'
Full Name , Email , Username , Checkout Location , Checkout Type , item Name , Category , Model name , Manufacturer , Model Number , Serial , Asset Tag , Location , Notes , Purchase Date , Purchase Cost , Company , Status , Warranty , Supplier , Weight
Bonnie Nelson , bnelson0 @ cdbaby . com , bnelson0 ,,, eget nunc donec quis , quam , massa id , Linkbridge , 6377018600094472 , 27 aa8378 - b0f4 - 4289 - 84 a4 - 405 da95c6147 , 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 , 35
Mildred Gibson , mgibson2 @ wiley . com , mgibson2 ,, user , morbi quis tortor id , nunc nisl duis , convallis tortor risus , Lajo , 374622546776765 , 2837 ab20 - 8 f0d - 4935 - 8 a52 - 226392 f2b1b0 , 710141467 - 2 , Shekou , In congue . Etiam justo . Etiam pretium iaculis justo . , 2015 - 08 - 09 , 233.57 , Konklab , Lost ,,,
,,, Planet Earth , location , dictumst maecenas ut , sem praesent , accumsan felis , Layo , 30052522651756 , 4751495 c - cee0 - 4961 - b788 - 94 a545b5643e , 998233705 - X , Dante Delgado ,, 2016 - 04 - 16 , 261.79 ,, Archived , 15 , Ntag ,
,,, Daping , location , viverra diam vitae , semper sapien , dapibus dolor vel , Flashset , 3559785746335392 , e287bb64 - ff4f - 434 c - 88 ab - 210 ad433c77b , 927820758 - 6 , Achiaman ,, 2016 - 03 - 05 , 675.3 ,, Archived , 22 , Meevee ,
EOT ;
$this -> import ( new AssetImporter ( $csv ));
2018-07-17 16:46:08 -07:00
2018-07-05 12:22:24 -07:00
$user = User :: where ( 'username' , 'bnelson0' ) -> firstOrFail ();
$this -> tester -> seeRecord ( 'assets' , [
'asset_tag' => '970882174-8' ,
'assigned_type' => User :: class ,
'assigned_to' => $user -> id
]);
$user = User :: where ( 'username' , 'mgibson2' ) -> firstOrFail ();
$this -> tester -> seeRecord ( 'assets' , [
'asset_tag' => '710141467-2' ,
'assigned_type' => User :: class ,
'assigned_to' => $user -> id
]);
$location = Location :: where ( 'name' , 'Planet Earth' ) -> firstOrFail ();
$this -> tester -> seeRecord ( 'assets' , [
'asset_tag' => '998233705-X' ,
'assigned_type' => Location :: class ,
'assigned_to' => $location -> id
]);
$location = Location :: where ( 'name' , 'Daping' ) -> firstOrFail ();
$this -> tester -> seeRecord ( 'assets' , [
'asset_tag' => '927820758-6' ,
'assigned_type' => Location :: class ,
'assigned_to' => $location -> id
]);
}
2017-09-18 12:29:08 -07:00
public function testUpdateAssetIncludingCustomFields ()
2017-09-06 16:24:43 -07:00
{
2018-01-25 10:10:56 -08:00
$this -> signIn ();
2017-09-06 16:24:43 -07:00
$csv = <<< 'EOT'
2017-11-24 10:42:11 -08:00
Name , Email , Username , item Name , Category , Model name , Manufacturer , Model Number , Serial , Asset Tag , Location , Notes , Purchase Date , Purchase Cost , Company , Status , Warranty , Supplier , weight
2017-09-18 12:29:08 -07:00
Bonnie Nelson , bnelson0 @ cdbaby . com , bnelson0 , eget nunc donec quis , quam , massa id , Linkbridge , 6377018600094472 , 27 aa8378 - b0f4 - 4289 - 84 a4 - 405 da95c6147 , 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 , 95
2017-09-06 16:24:43 -07:00
EOT ;
2017-09-18 12:29:08 -07:00
$this -> initializeCustomFields ();
2017-09-06 16:24:43 -07:00
$this -> import ( new AssetImporter ( $csv ));
2018-03-27 16:52:44 -07:00
2017-09-06 16:24:43 -07:00
$updatedCSV = <<< 'EOT'
2017-11-24 10:42:11 -08:00
item Name , Category , Model name , Manufacturer , Model Number , Serial , Asset Tag , Location , Notes , Purchase Date , Purchase Cost , Company , Status , Warranty , Supplier
2017-09-06 16:24:43 -07:00
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 ( 'models' , [
'name' => 'Another Model' ,
'model_number' => 356
]);
$this -> tester -> seeRecord ( 'manufacturers' , [
'name' => 'Linkbridge 32'
]);
$this -> tester -> seeRecord ( 'locations' , [
'name' => 'New Location'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Another Company'
]);
$this -> tester -> seeRecord ( 'status_labels' , [
'name' => 'Ready To Go'
]);
$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 ,
2017-09-18 12:29:08 -07:00
'warranty_months' => 18 ,
'_snipeit_weight_2' => 95
]);
2017-09-06 16:24:43 -07:00
}
2017-11-24 10:42:11 -08:00
public function testAssetModelNumber4359 ()
{
// As per bug #4359
// 1) Create model with blank model # and custom field.
// 2 ) Update custom fields with a csv not including model #
// 3 ) Not updated. NULL vs. empty issue.
2018-01-25 10:10:56 -08:00
$this -> signIn ();
2017-11-24 10:42:11 -08:00
$csv = <<< 'EOT'
Name , Email , Username , item Name , Category , Model name , Manufacturer , Serial , 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 , 27 aa8378 - b0f4 - 4289 - 84 a4 - 405 da95c6147 , 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 ;
// Need to do this manually...
$customField = factory ( App\Models\CustomField :: class ) -> create ([ 'name' => 'Weight' ]);
$customFieldSet = factory ( App\Models\CustomFieldset :: class ) -> create ([ 'name' => 'Default' ]);
$customFieldSet -> fields () -> attach ( $customField , [
'required' => false ,
'order' => 'asc' ]);
factory ( App\Models\Category :: class ) -> states ( 'asset-laptop-category' ) -> create ([
'name' => 'quam'
]);
factory ( App\Models\Manufacturer :: class ) -> states ( 'apple' ) -> create ([
'name' => 'Linkbridge'
]);
$am = factory ( App\Models\AssetModel :: class ) -> create ([
'name' => 'massa id' ,
'fieldset_id' => $customFieldSet -> id ,
'category_id' => 1 ,
'manufacturer_id' => 1 ,
'model_number' => null
]);
$this -> import ( new AssetImporter ( $csv ));
$updatedCSV = <<< 'EOT'
Serial , Asset Tag , weight
67433477 , 970882174 - 8 , 115
EOT ;
$importer = new AssetImporter ( $updatedCSV );
$importer -> setUserId ( 1 )
-> setUpdating ( true )
-> setUsernameFormat ( 'firstname.lastname' )
-> import ();
$this -> tester -> seeRecord ( 'assets' , [
'asset_tag' => '970882174-8' ,
'_snipeit_weight_2' => 115
]);
}
2017-09-18 16:40:13 -07:00
public function initializeCustomFields ()
{
2017-09-18 12:29:08 -07:00
$customField = factory ( App\Models\CustomField :: class ) -> create ([ 'name' => 'Weight' ]);
$customFieldSet = factory ( App\Models\CustomFieldset :: class ) -> create ([ 'name' => 'Default' ]);
$customFieldSet -> fields () -> attach ( $customField , [
'required' => false ,
'order' => 'asc' ]);
$am = factory ( App\Models\AssetModel :: class ) -> create ([
'name' => 'massa id' ,
'fieldset_id' => $customFieldSet -> id
]);
2017-09-18 16:40:13 -07:00
}
2017-09-06 16:24:43 -07:00
public function testCustomMappingImport ()
{
2018-01-25 10:10:56 -08:00
$this -> signIn ();
2017-09-06 16:24:43 -07:00
$csv = <<< 'EOT'
2018-02-21 16:42:36 -08:00
Full Name , Email , Username , object name , Cat , Model name , Manufacturer , Model Number , Serial , Asset , Loc , Some Notes , Purchase Date , Purchase Cost , comp , Status , Warranty , Supplier
2017-09-06 16:24:43 -07:00
Bonnie Nelson , bnelson0 @ cdbaby . com , bnelson0 , eget nunc donec quis , quam , massa id , Linkbridge , 6377018600094472 , 27 aa8378 - b0f4 - 4289 - 84 a4 - 405 da95c6147 , 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 " ,
];
$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' ,
]);
2017-09-18 16:40:13 -07:00
// Grab the user record for use in asserting assigned_to
$createdUser = $this -> tester -> grabRecord ( 'users' , [
'first_name' => 'Bonnie' ,
'last_name' => 'Nelson' ,
'email' => 'bnelson0@cdbaby.com' ,
]);
2017-09-06 16:24:43 -07:00
$this -> tester -> seeRecord ( 'categories' , [
'name' => 'quam'
]);
$this -> tester -> seeRecord ( 'models' , [
'name' => 'massa id' ,
'model_number' => 6377018600094472
]);
$this -> tester -> seeRecord ( 'manufacturers' , [
'name' => 'Linkbridge'
]);
$this -> tester -> seeRecord ( 'locations' , [
'name' => 'Daping'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Alpha'
]);
$this -> tester -> seeRecord ( 'status_labels' , [
'name' => 'Undeployable'
]);
$this -> tester -> seeRecord ( 'suppliers' , [
'name' => 'Blogspan'
]);
2017-09-18 16:40:13 -07:00
2017-09-06 16:24:43 -07:00
$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 ,
2017-09-18 16:40:13 -07:00
'warranty_months' => 14 ,
'assigned_to' => $createdUser [ 'id' ],
'assigned_type' => User :: class
]);
2017-09-06 16:24:43 -07:00
}
2017-07-11 20:37:02 -07:00
public function testDefaultAccessoryImport ()
{
$csv = <<< 'EOT'
Item Name , Purchase Date , Purchase Cost , Location , Company , Order Number , Category , Requestable , Quantity
Walter Carter , 09 / 01 / 2006 ,, metus . Vivamus , Macromedia , J935H60W , Customers , False , 278
EOT ;
$this -> import ( new AccessoryImporter ( $csv ));
$this -> tester -> seeRecord ( 'accessories' , [
'name' => 'Walter Carter' ,
'purchase_date' => '2006-09-01 00:00:01' ,
'order_number' => 'J935H60W' ,
'requestable' => 0 ,
'qty' => 278
]);
$this -> tester -> seeRecord ( 'locations' , [
'name' => 'metus. Vivamus'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Macromedia'
]);
$this -> tester -> seeRecord ( 'categories' , [
'name' => 'Customers'
]);
}
public function testDefaultAccessoryUpdate ()
{
$csv = <<< 'EOT'
Item Name , Purchase Date , Purchase Cost , Location , Company , Order Number , Category , Requestable , Quantity
Walter Carter , 09 / 01 / 2006 ,, metus . Vivamus , Macromedia , J935H60W , Customers , False , 278
EOT ;
$this -> import ( new AccessoryImporter ( $csv ));
$this -> tester -> seeNumRecords ( 1 , 'accessories' );
$updatedCSV = <<< 'EOT'
Item Name , Purchase Date , Purchase Cost , Location , Company , Order Number , Category , Requestable , Quantity
Walter Carter , 09 / 01 / 2015 , 350 , metus . Vivamus , Macromedia , 35 GGH , Customers , True , 12
EOT ;
$importer = new AccessoryImporter ( $updatedCSV );
$importer -> setUserId ( 1 )
-> setUpdating ( true )
-> import ();
// At this point we should still only have one record.
$this -> tester -> seeNumRecords ( 1 , 'accessories' );
// But instead these.
$this -> tester -> seeRecord ( 'accessories' , [
'name' => 'Walter Carter' ,
'purchase_date' => '2015-09-01 00:00:01' ,
'order_number' => '35GGH' ,
'requestable' => 1 ,
'qty' => 12
]);
}
public function testCustomAccessoryImport ()
{
$csv = <<< 'EOT'
Name , Pur Date , Cost , Loc , Comp , Order Num , Cat , Request , Quan
Walter Carter , 09 / 01 / 2006 ,, metus . Vivamus , Macromedia , J935H60W , Customers , False , 278
EOT ;
$customFieldMap = [
'category' => 'Cat' ,
'company' => 'Comp' ,
'item_name' => 'Name' ,
'location' => 'Loc' ,
'purchase_date' => 'Pur Date' ,
'purchase_cost' => " Cost " ,
'order_number' => 'Order Num' ,
'requestable' => 'Request' ,
'quantity' => 'Quan'
];
$this -> import ( new AccessoryImporter ( $csv ), $customFieldMap );
// dd($this->tester->grabRecord('accessories'));
$this -> tester -> seeRecord ( 'accessories' , [
'name' => 'Walter Carter' ,
'purchase_date' => '2006-09-01 00:00:01' ,
'order_number' => 'J935H60W' ,
'requestable' => 0 ,
'qty' => 278
]);
$this -> tester -> seeRecord ( 'locations' , [
'name' => 'metus. Vivamus'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Macromedia'
]);
$this -> tester -> seeRecord ( 'categories' , [
'name' => 'Customers'
]);
}
public function testDefaultConsumableImport ()
{
$csv = <<< 'EOT'
2018-07-05 12:22:24 -07:00
Item Name , Purchase Date , Purchase Cost , Location , Company , Order Number , Category , Requestable , Quantity , Item Number , Model Number
eget , 01 / 03 / 2011 , $ 85.91 , mauris blandit mattis . , Lycos , T295T06V , Triamterene / Hydrochlorothiazide , No , 322 , 3305 , 30123
2017-07-11 20:37:02 -07:00
EOT ;
$this -> import ( new ConsumableImporter ( $csv ));
$this -> tester -> seeRecord ( 'consumables' , [
'name' => 'eget' ,
'purchase_date' => '2011-01-03 00:00:01' ,
'purchase_cost' => 85.91 ,
'order_number' => 'T295T06V' ,
'requestable' => 0 ,
2018-07-05 12:22:24 -07:00
'qty' => 322 ,
'item_no' => 3305 ,
'model_number' => 30123
2017-07-11 20:37:02 -07:00
]);
$this -> tester -> seeRecord ( 'locations' , [
'name' => 'mauris blandit mattis.'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Lycos'
]);
$this -> tester -> seeRecord ( 'categories' , [
'name' => 'Triamterene/Hydrochlorothiazide'
]);
}
public function testDefaultConsumableUpdate ()
{
$csv = <<< 'EOT'
Item Name , Purchase Date , Purchase Cost , Location , Company , Order Number , Category , Requestable , Quantity
eget , 01 / 03 / 2011 , 85.91 , mauris blandit mattis . , Lycos , T295T06V , Triamterene / Hydrochlorothiazide , No , 322
EOT ;
$this -> import ( new ConsumableImporter ( $csv ));
$this -> tester -> seeNumRecords ( 1 , 'consumables' );
$updatedCSV = <<< 'EOT'
Item Name , Purchase Date , Purchase Cost , Location , Company , Order Number , Category , Requestable , Quantity
eget , 12 / 05 / 2016 , 35.45 , mauris blandit mattis . , Lycos , 3666 FF , New Cat , Yes , 15
EOT ;
$importer = new ConsumableImporter ( $updatedCSV );
$importer -> setUserId ( 1 )
-> setUpdating ( true )
-> import ();
// At this point we should still only have one record.
$this -> tester -> seeNumRecords ( 1 , 'consumables' );
// But instead these.
$this -> tester -> seeRecord ( 'consumables' , [
'name' => 'eget' ,
'purchase_date' => '2016-12-05 00:00:01' ,
'purchase_cost' => 35.45 ,
'order_number' => '3666FF' ,
'requestable' => 1 ,
'qty' => 15
]);
}
public function testCustomConsumableImport ()
{
$csv = <<< 'EOT'
Name , pur Date , Pur Cost , Loc , Comp , Order Num , Kat , Request , Quan
eget , 01 / 03 / 2011 , 85.91 , mauris blandit mattis . , Lycos , T295T06V , Triamterene / Hydrochlorothiazide , No , 322
EOT ;
$customFieldMap = [
'category' => 'Kat' ,
'company' => 'Comp' ,
'item_name' => 'Name' ,
'location' => 'Loc' ,
'purchase_date' => 'Pur date' ,
'purchase_cost' => " Pur Cost " ,
'order_number' => 'Order Num' ,
'requestable' => 'Request' ,
'quantity' => 'Quan'
];
$this -> import ( new ConsumableImporter ( $csv ), $customFieldMap );
$this -> tester -> seeRecord ( 'consumables' , [
'name' => 'eget' ,
'purchase_date' => '2011-01-03 00:00:01' ,
'purchase_cost' => 85.91 ,
'order_number' => 'T295T06V' ,
'requestable' => 0 ,
'qty' => 322
]);
$this -> tester -> seeRecord ( 'locations' , [
'name' => 'mauris blandit mattis.'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Lycos'
]);
$this -> tester -> seeRecord ( 'categories' , [
'name' => 'Triamterene/Hydrochlorothiazide'
]);
}
public function testDefaultLicenseImport ()
{
2018-01-25 10:10:56 -08:00
$this -> signIn ();
2017-07-11 20:37:02 -07:00
$csv = <<< 'EOT'
2018-05-16 18:35:11 -07:00
Name , Email , Username , Item name , serial , manufacturer , purchase date , purchase cost , purchase order , order number , Licensed To Name , Licensed to Email , expiration date , maintained , reassignable , seats , company , supplier , category , notes
Helen Anderson , cspencer0 @ privacy . gov . au , cspencer0 , Argentum Malachite Athletes Foot Relief , 1 aa5b0eb - 79 c5 - 40 b2 - 8943 - 5472 a6893c3c , " Beer, Leannon and Lubowitz " , 07 / 13 / 2012 , $ 79.66 , 53008 , 386436062 - 5 , Cynthia Spencer , cspencer0 @ gov . uk , 01 / 27 / 2016 , false , no , 80 , " Haag, Schmidt and Farrell " , " Hegmann, Mohr and Cremin " , Graphics Software , Sed ante . Vivamus tortor . Duis mattis egestas metus .
2017-07-11 20:37:02 -07:00
EOT ;
$this -> import ( new LicenseImporter ( $csv ));
// dd($this->tester->grabRecord('licenses'));
$this -> tester -> seeRecord ( 'licenses' , [
'name' => 'Argentum Malachite Athletes Foot Relief' ,
'purchase_date' => '2012-07-13 00:00:01' ,
'seats' => 80 ,
'license_email' => 'cspencer0@gov.uk' ,
'order_number' => '386436062-5' ,
'license_name' => 'Cynthia Spencer' ,
'expiration_date' => '2016-01-27' ,
'maintained' => 0 ,
'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.' ,
'purchase_cost' => 79.66 ,
'purchase_order' => " 53008 " ,
'reassignable' => 0 ,
'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c' ,
]);
$this -> tester -> seeRecord ( 'manufacturers' , [
'name' => 'Beer, Leannon and Lubowitz'
]);
$this -> tester -> seeRecord ( 'suppliers' , [
'name' => " Hegmann, Mohr and Cremin " ,
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Haag, Schmidt and Farrell'
]);
2018-05-16 18:35:11 -07:00
$this -> tester -> seeRecord ( 'categories' , [
'name' => 'Graphics Software'
]);
2017-07-11 20:37:02 -07:00
$this -> tester -> seeNumRecords ( 80 , 'license_seats' );
}
public function testDefaultLicenseUpdate ()
{
$csv = <<< 'EOT'
2018-05-16 19:05:00 -07:00
Name , Email , Username , Item name , serial , manufacturer , purchase date , purchase cost , purchase order , order number , Licensed To Name , Licensed to Email , expiration date , maintained , reassignable , seats , company , supplier , category , notes
Helen Anderson , cspencer0 @ privacy . gov . au , cspencer0 , Argentum Malachite Athletes Foot Relief , 1 aa5b0eb - 79 c5 - 40 b2 - 8943 - 5472 a6893c3c , " Beer, Leannon and Lubowitz " , 07 / 13 / 2012 , $ 79.66 , 53008 , 386436062 - 5 , Cynthia Spencer , cspencer0 @ gov . uk , 01 / 27 / 2016 , false , no , 80 , " Haag, Schmidt and Farrell " , " Hegmann, Mohr and Cremin " , Graphics Software , Sed ante . Vivamus tortor . Duis mattis egestas metus .
2017-07-11 20:37:02 -07:00
EOT ;
$this -> import ( new LicenseImporter ( $csv ));
$this -> tester -> seeNumRecords ( 1 , 'licenses' );
$updatedCSV = <<< 'EOT'
2018-05-16 19:05:00 -07:00
Item name , serial , manufacturer , purchase date , purchase cost , purchase order , order number , Licensed To Name , Licensed to Email , expiration date , maintained , reassignable , seats , company , supplier , category , notes
Argentum Malachite Athletes Foot Relief , 1 aa5b0eb - 79 c5 - 40 b2 - 8943 - 5472 a6893c3c , " Beer, Leannon and Lubowitz " , 05 / 15 / 2019 , $ 1865.34 , 63 ar , 18334 , A Legend , Legendary @ gov . uk , 04 / 27 / 2016 , yes , true , 64 , " Haag, Schmidt and Farrell " , " Hegmann, Mohr and Cremin " , Graphics Software , Sed ante . Vivamus tortor . Duis mattis egestas metus .
2017-07-11 20:37:02 -07:00
EOT ;
$importer = new LicenseImporter ( $updatedCSV );
$importer -> setUserId ( 1 )
-> setUpdating ( true )
-> import ();
// At this point we should still only have one record.
$this -> tester -> seeNumRecords ( 1 , 'licenses' );
// But instead these.
2018-05-16 19:05:00 -07:00
\Log :: debug ( $this -> tester -> grabRecord ( 'licenses' ));
2017-07-11 20:37:02 -07:00
$this -> tester -> seeRecord ( 'licenses' , [
'name' => 'Argentum Malachite Athletes Foot Relief' ,
'purchase_date' => '2019-05-15 00:00:01' ,
'seats' => 64 ,
'license_email' => 'Legendary@gov.uk' ,
'order_number' => '18334' ,
'license_name' => 'A Legend' ,
'expiration_date' => '2016-04-27' ,
'maintained' => 1 ,
'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.' ,
'purchase_cost' => 1865.34 ,
'purchase_order' => " 63 ar " ,
'reassignable' => 1 ,
2017-10-03 09:14:04 -07:00
'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c' ,
2017-07-11 20:37:02 -07:00
]);
// License seats are soft deleted
$this -> tester -> seeNumRecords ( 64 , 'license_seats' , [ 'deleted_at' => null ]);
}
public function testCustomLicenseImport ()
{
$csv = <<< 'EOT'
2018-05-16 19:05:00 -07:00
Name , Email , Username , Object name , serial num , manuf , pur date , pur cost , purc order , order num , Licensed To , Licensed Email , expire date , maint , reass , seat , comp , supplier , category , note
Helen Anderson , cspencer0 @ privacy . gov . au , cspencer0 , Argentum Malachite Athletes Foot Relief , 1 aa5b0eb - 79 c5 - 40 b2 - 8943 - 5472 a6893c3c , " Beer, Leannon and Lubowitz " , 07 / 13 / 2012 , $ 79.66 , 53008 , 386436062 - 5 , Cynthia Spencer , cspencer0 @ gov . uk , 01 / 27 / 2016 , false , no , 80 , " Haag, Schmidt and Farrell " , " Hegmann, Mohr and Cremin " , Custom Graphics Software , Sed ante . Vivamus tortor . Duis mattis egestas metus .
2017-07-11 20:37:02 -07:00
EOT ;
$customFieldMap = [
'company' => 'Comp' ,
'expiration_date' => 'expire date' ,
'item_name' => 'Object Name' ,
'license_email' => 'licensed email' ,
'license_name' => 'licensed to' ,
'maintained' => 'maint' ,
'manufacturer' => 'manuf' ,
'notes' => 'note' ,
'order_number' => 'Order Num' ,
'purchase_cost' => " Pur Cost " ,
'purchase_date' => 'Pur date' ,
'purchase_order' => " Purc Order " ,
'quantity' => 'Quan' ,
'reassignable' => 'reass' ,
'requestable' => 'Request' ,
'seats' => 'seat' ,
2017-11-24 10:42:11 -08:00
'serial' => 'serial num' ,
2018-05-16 19:05:00 -07:00
'category' => 'category' ,
2017-07-11 20:37:02 -07:00
];
$this -> import ( new LicenseImporter ( $csv ), $customFieldMap );
$this -> tester -> seeRecord ( 'licenses' , [
'name' => 'Argentum Malachite Athletes Foot Relief' ,
'purchase_date' => '2012-07-13 00:00:01' ,
'seats' => 80 ,
'license_email' => 'cspencer0@gov.uk' ,
'order_number' => '386436062-5' ,
'license_name' => 'Cynthia Spencer' ,
'expiration_date' => '2016-01-27' ,
'maintained' => 0 ,
'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.' ,
'purchase_cost' => 79.66 ,
'purchase_order' => " 53008 " ,
'reassignable' => 0 ,
'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c' ,
]);
$this -> tester -> seeRecord ( 'manufacturers' , [
'name' => 'Beer, Leannon and Lubowitz'
]);
$this -> tester -> seeRecord ( 'suppliers' , [
'name' => " Hegmann, Mohr and Cremin " ,
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Haag, Schmidt and Farrell'
]);
$this -> tester -> seeNumRecords ( 80 , 'license_seats' );
}
2018-07-18 19:15:07 -07:00
public function testDefaultUserImport ()
{
Notification :: fake ();
$this -> signIn ();
$csv = <<< 'EOT'
2018-07-27 12:02:18 -07:00
First Name , Last Name , email , Username , Location , Phone Number , Job Title , Employee Number , Company , Department
Blanche , O ' Collopy , bocollopy0 @ livejournal . com , bocollopy0 , Hinapalanan , 63 - ( 199 ) 661 - 2186 , Clinical Specialist , 7080919053 , Morar - Ward , Management
2018-07-18 19:15:07 -07:00
Jessie , Primo ,, jprimo1 , Korenovsk , 7 - ( 885 ) 578 - 0266 , Paralegal , 6284292031 , Jast - Stiedemann
EOT ;
$this -> import ( new UserImporter ( $csv ));
$this -> tester -> seeRecord ( 'users' , [
'first_name' => 'Blanche' ,
'last_name' => " O'Collopy " ,
'email' => 'bocollopy0@livejournal.com' ,
'username' => 'bocollopy0' ,
'phone' => '63-(199)661-2186' ,
'jobtitle' => 'Clinical Specialist' ,
'employee_num' => '7080919053'
]);
$this -> tester -> seeRecord ( 'companies' , [
'name' => 'Morar-Ward'
]);
2018-07-27 12:02:18 -07:00
$this -> tester -> seeRecord ( 'departments' , [
'name' => 'Management'
]);
2018-07-18 19:15:07 -07:00
Notification :: assertSentTo ( User :: find ( 2 ), \App\Notifications\WelcomeNotification :: class );
Notification :: assertNotSentTo ( User :: find ( 3 ), \App\Notifications\WelcomeNotification :: class );
}
2017-07-11 20:37:02 -07:00
private function import ( $importer , $mappings = null )
{
if ( $mappings ) {
$importer -> setFieldMappings ( $mappings );
}
$importer -> setUserId ( 1 )
-> setUpdating ( false )
-> setUsernameFormat ( 'firstname.lastname' )
-> import ();
}
}