Skip to content

A free open source IT asset/license management system

Bugfixes based on functional tests (#3338)

Andrea Bergamascoe7f7d739ed0c
diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php
index f13520353b..a9d4751677 100755
--- a/app/Http/Controllers/CategoriesController.php
+++ b/app/Http/Controllers/CategoriesController.php
@@ -173,7 +173,7 @@ class CategoriesController extends Controller
$category->delete();
// Redirect to the locations management page
- return redirect()->to('admin/settings/categories')->with('success', trans('admin/categories/message.delete.success'));
+ return redirect()->to(route('categories.index'))->with('success', trans('admin/categories/message.delete.success'));
}
diff --git a/app/Http/Controllers/GroupsController.php b/app/Http/Controllers/GroupsController.php
index 1140310b7a..0514eaa81b 100755
--- a/app/Http/Controllers/GroupsController.php
+++ b/app/Http/Controllers/GroupsController.php
@@ -72,7 +72,7 @@ class GroupsController extends Controller
if ($group->save()) {
return redirect()->route("groups.index")->with('success', trans('admin/groups/message.success.create'));
}
- return redirect()->back()->withInput()->withErrors($group->getErrors());
+ return redirect(route('groups.create'))->withInput()->withErrors($group->getErrors());
}
/**
diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php
index 0277460cda..7851719dae 100755
--- a/app/Http/Controllers/LocationsController.php
+++ b/app/Http/Controllers/LocationsController.php
@@ -208,21 +208,21 @@ class LocationsController extends Controller
// Check if the location exists
if (is_null($location = Location::find($locationId))) {
// Redirect to the blogs management page
- return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.not_found'));
+ return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.not_found'));
}
if ($location->users->count() > 0) {
- return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_users'));
+ return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_users'));
} elseif ($location->childLocations->count() > 0) {
- return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_child_loc'));
+ return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_child_loc'));
} elseif ($location->assets->count() > 0) {
- return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_assets'));
+ return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_assets'));
} elseif ($location->assignedassets->count() > 0) {
- return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.assoc_assets'));
+ return redirect()->to(route('locations.index'))->with('error', trans('admin/locations/message.assoc_assets'));
} else {
$location->delete();
- return redirect()->to('admin/settings/locations')->with('success', trans('admin/locations/message.delete.success'));
+ return redirect()->to(route('locations.index'))->with('success', trans('admin/locations/message.delete.success'));
}
}
diff --git a/resources/views/groups/edit.blade.php b/resources/views/groups/edit.blade.php
index 38d137fed1..f8e63795d5 100755
--- a/resources/views/groups/edit.blade.php
+++ b/resources/views/groups/edit.blade.php
@@ -4,7 +4,7 @@
'helpTitle' => trans('admin/groups/general.about_groups_title'),
'helpText' => trans('admin/groups/general.about_groups_text'),
'item' => $group,
- 'formAction' => ($group) ? route('groups.update', ['accessory' => $group->id]) : route('groups.store'),
+ 'formAction' => ($group !== null && $group->id !== null) ? route('groups.update', ['accessory' => $group->id]) : route('groups.store'),
])
@section('content')
diff --git a/tests/functional/AccessoriesCest.php b/tests/functional/AccessoriesCest.php
index bdbd66154d..961874eca7 100644
--- a/tests/functional/AccessoriesCest.php
+++ b/tests/functional/AccessoriesCest.php
@@ -9,14 +9,16 @@ class AccessoriesCest
$I->fillField('username', 'snipeit');
$I->fillField('password', 'snipeit');
$I->click('Login');
+ $I->seeAuthentication();
}
// tests
- public function tryToTest(FunctionalTester $I)
+ public function loadsFormWithoutErrors(FunctionalTester $I)
{
$I->wantTo('ensure that the create accessories form loads without errors');
$I->lookForwardTo('seeing it load without errors');
$I->amOnPage('/accessories/create');
+ $I->seeResponseCodeIs(200);
$I->dontSee('Create Accessory', '.page-header');
$I->see('Create Accessory', 'h1.pull-left');
}
@@ -25,6 +27,7 @@ class AccessoriesCest
{
$I->wantTo("Test Validation Fails with blank elements");
$I->amOnPage('/accessories/create');
+ $I->seeResponseCodeIs(200);
$I->click('Save');
$I->seeElement('.alert-danger');
$I->see('The name field is required.', '.alert-msg');
@@ -36,6 +39,7 @@ class AccessoriesCest
{
$I->wantTo("Test Validation Fails with short name");
$I->amOnPage('/accessories/create');
+ $I->seeResponseCodeIs(200);
$I->fillField('name', 't2');
$I->fillField('qty', '-15');
$I->fillField('min_amt', '-15');
@@ -65,6 +69,7 @@ class AccessoriesCest
$I->wantTo("Test Validation Succeeds");
$I->amOnPage('/accessories/create');
+ $I->seeResponseCodeIs(200);
$I->submitForm('form#create-form', $values);
$I->seeRecord('accessories', $values);
diff --git a/tests/functional/CategoriesCest.php b/tests/functional/CategoriesCest.php
index f51e0e4c81..bea932aa08 100644
--- a/tests/functional/CategoriesCest.php
+++ b/tests/functional/CategoriesCest.php
@@ -1,7 +1,7 @@
<?php
-class CategoryCest
+class CategoriesCest
{
public function _before(FunctionalTester $I)
{
@@ -37,7 +37,7 @@ class CategoryCest
public function passesCorrectValidation(FunctionalTester $I)
{
- $category = factory(App\Models\Category::class, 'asset-category')->make();
+ $category = factory(App\Models\Category::class, 'category')->make();
$values = [
'name' => $category->name,
'category_type' => $category->category_type,
@@ -55,7 +55,7 @@ class CategoryCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a category');
- $category = factory(App\Models\Category::class, 'asset-category')->create();
+ $category = factory(App\Models\Category::class, 'category')->create();
$I->sendDelete(route('categories.destroy', $category->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200);
}
diff --git a/tests/functional/GroupsCest.php b/tests/functional/GroupsCest.php
index cab4752b9f..76a18971d3 100644
--- a/tests/functional/GroupsCest.php
+++ b/tests/functional/GroupsCest.php
@@ -14,11 +14,12 @@ class GroupsCest
}
// tests
- public function tryToTest(FunctionalTester $I)
+ public function loadsFormWithoutErrors(FunctionalTester $I)
{
$I->wantTo('ensure that the create groups form loads without errors');
$I->lookForwardTo('seeing it load without errors');
- $I->amOnPage(route('create/group'));
+ $I->amOnPage(route('groups.create'));
+ $I->seeResponseCodeIs(200);
$I->dontSee('Create New Group', '.page-header');
$I->see('Create New Group', 'h1.pull-left');
}
@@ -26,7 +27,8 @@ class GroupsCest
public function failsEmptyValidation(FunctionalTester $I)
{
$I->wantTo("Test Validation Fails with blank elements");
- $I->amOnPage(route('create/group'));
+ $I->amOnPage(route('groups.create'));
+ $I->seeResponseCodeIs(200);
$I->click('Save');
$I->seeElement('.alert-danger');
$I->see('The name field is required.', '.alert-msg');
@@ -35,7 +37,8 @@ class GroupsCest
public function failsShortValidation(FunctionalTester $I)
{
$I->wantTo("Test Validation Fails with short name");
- $I->amOnPage(route('create/group'));
+ $I->amOnPage(route('groups.create'));
+ $I->seeResponseCodeIs(200);
$I->fillField('name', 't2');
$I->click('Save');
$I->seeElement('.alert-danger');
@@ -45,19 +48,37 @@ class GroupsCest
public function passesCorrectValidation(FunctionalTester $I)
{
$I->wantTo("Test Validation Succeeds");
- $I->amOnPage(route('create/group'));
+ $I->amOnPage(route('groups.create'));
+ $I->seeResponseCodeIs(200);
$I->fillField('name', 'TestGroup');
$I->click('Save');
$I->dontSee('&lt;span class=&quot;');
$I->seeElement('.alert-success');
}
- public function allowsDelete(FunctionalTester $I)
+ public function allowsDelete(FunctionalTester $I, $scenario)
{
- $I->wantTo("Fix this test to generate a group for deletes");
+ $scenario->incomplete('Fix this test to generate a group for deletes');
$I->wantTo('Ensure I can delete a group');
-// $I->amOnPage(route('delete/group', Group::doesntHave('users')->first()->id));
-// $I->seeElement('.alert-success');
+
+ // create a group
+ $I->amOnPage(route('groups.create'));
+ $I->seeResponseCodeIs(200);
+ $I->fillField('name', 'TestGroup');
+ $I->click('Save');
+ $I->dontSee('&lt;span class=&quot;');
+ $I->seeElement('.alert-success');
+
+ // delete it
+ $I->amOnPage(route('groups.delete', Group::doesntHave('users')->first()->id));
+ $I->seeResponseCodeIs(200);
+ $I->seeElement('.alert-success');
+ // $I->seeResponseCodeIs(200);
}
+ public function allowsEditing(FunctionalTester $I, $scenario)
+ {
+ $scenario->incomplete('Fix this test to generate a group for editing');
+ $I->wantTo('Ensure i can edit a group');
+ }
}
diff --git a/tests/functional/LicensesCest.php b/tests/functional/LicensesCest.php
index 15bca2d13d..d5c735e9a7 100644
--- a/tests/functional/LicensesCest.php
+++ b/tests/functional/LicensesCest.php
@@ -3,7 +3,7 @@
use App\Models\License;
-class licensesCest
+class LicensesCest
{
public function _before(FunctionalTester $I)
{
diff --git a/tests/functional/_bootstrap.php b/tests/functional/_bootstrap.php
index f7cbed7bb2..8a88555806 100644
--- a/tests/functional/_bootstrap.php
+++ b/tests/functional/_bootstrap.php
@@ -1,6 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests
-function _beforeSuite(FunctionalTester $I)
-{
- echo "Hello";
-}
\ No newline at end of file