mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 16:14:18 -08:00
Merge remote-tracking branch 'origin/develop'
Signed-off-by: snipe <snipe@snipe.net> # Conflicts: # config/version.php # public/js/build/app.js # public/js/dist/all.js # public/mix-manifest.json
This commit is contained in:
commit
785ba3b5ed
75
.env.testing
75
.env.testing
|
@ -1,75 +0,0 @@
|
|||
# --------------------------------------------
|
||||
# REQUIRED: BASIC APP SETTINGS
|
||||
# --------------------------------------------
|
||||
APP_ENV=testing
|
||||
APP_DEBUG=true
|
||||
APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU=
|
||||
APP_URL=http://localhost:8000
|
||||
APP_TIMEZONE='US/Pacific'
|
||||
APP_LOCALE=en
|
||||
FILESYSTEM_DISK=local
|
||||
|
||||
# --------------------------------------------
|
||||
# REQUIRED: DATABASE SETTINGS
|
||||
# --------------------------------------------
|
||||
DB_CONNECTION=sqlite_testing
|
||||
DB_HOST=localhost
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=testing.sqlite
|
||||
DB_USERNAME=null
|
||||
DB_PASSWORD=null
|
||||
|
||||
# --------------------------------------------
|
||||
# REQUIRED: OUTGOING MAIL SERVER SETTINGS
|
||||
# --------------------------------------------
|
||||
MAIL_DRIVER=log
|
||||
MAIL_HOST=email-smtp.us-west-2.amazonaws.com
|
||||
MAIL_PORT=587
|
||||
MAIL_USERNAME=YOURUSERNAME
|
||||
MAIL_PASSWORD=YOURPASSWORD
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDR=you@example.com
|
||||
MAIL_FROM_NAME=Snipe-IT
|
||||
|
||||
# --------------------------------------------
|
||||
# REQUIRED: IMAGE LIBRARY
|
||||
# This should be gd or imagick
|
||||
# --------------------------------------------
|
||||
IMAGE_LIB=gd
|
||||
|
||||
|
||||
# --------------------------------------------
|
||||
# OPTIONAL: AWS SETTINGS
|
||||
# --------------------------------------------
|
||||
AWS_SECRET_ACCESS_KEY=null
|
||||
AWS_ACCESS_KEY_ID=null
|
||||
AWS_DEFAULT_REGION=null
|
||||
AWS_BUCKET=null
|
||||
AWS_BUCKET_ROOT=null
|
||||
AWS_URL=null
|
||||
|
||||
|
||||
# --------------------------------------------
|
||||
# OPTIONAL: CACHE SETTINGS
|
||||
# --------------------------------------------
|
||||
CACHE_DRIVER=file
|
||||
SESSION_DRIVER=file
|
||||
QUEUE_DRIVER=sync
|
||||
|
||||
|
||||
# --------------------------------------------
|
||||
# OPTIONAL: SESSION SETTINGS
|
||||
# --------------------------------------------
|
||||
SESSION_LIFETIME=12000
|
||||
EXPIRE_ON_CLOSE=false
|
||||
ENCRYPT=false
|
||||
COOKIE_NAME=snipeittest_session
|
||||
COOKIE_DOMAIN=null
|
||||
SECURE_COOKIES=false
|
||||
|
||||
|
||||
# --------------------------------------------
|
||||
# OPTIONAL: APP LOG FORMAT
|
||||
# --------------------------------------------
|
||||
LOG_CHANNEL=single
|
||||
LOG_LEVEL=debug
|
19
.env.testing.example
Normal file
19
.env.testing.example
Normal file
|
@ -0,0 +1,19 @@
|
|||
# --------------------------------------------
|
||||
# REQUIRED: BASIC APP SETTINGS
|
||||
# --------------------------------------------
|
||||
APP_ENV=testing
|
||||
APP_DEBUG=true
|
||||
APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU=
|
||||
APP_URL=http://localhost:8000
|
||||
APP_TIMEZONE='UTC'
|
||||
APP_LOCALE=en
|
||||
|
||||
# --------------------------------------------
|
||||
# REQUIRED: DATABASE SETTINGS
|
||||
# --------------------------------------------
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=null
|
||||
DB_USERNAME=null
|
||||
DB_PASSWORD=null
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
|||
.env
|
||||
.env.dusk.*
|
||||
!.env.dusk.example
|
||||
.env.testing
|
||||
phpstan.neon
|
||||
.idea
|
||||
/bin/
|
||||
|
|
50
TESTING.md
50
TESTING.md
|
@ -1,45 +1,23 @@
|
|||
# Using the Test Suite
|
||||
# Running the Test Suite
|
||||
|
||||
This document is targeted at developers looking to make modifications to
|
||||
this application's code base and want to run the existing test suite.
|
||||
This document is targeted at developers looking to make modifications to this application's code base and want to run the existing test suite.
|
||||
|
||||
Before starting, follow the [instructions](README.md#installation) for installing the application locally and ensure you can load it in a browser properly.
|
||||
|
||||
## Setup
|
||||
## Unit and Feature Tests
|
||||
|
||||
Follow the instructions for installing the application locally,
|
||||
making sure to have also run the [database migrations](link to db migrations).
|
||||
Before attempting to run the test suite copy the example environment file for tests and update the values to match your environment:
|
||||
|
||||
`cp .env.testing.example .env.testing`
|
||||
> Since the data in the database is flushed after each test it is recommended you create a separate mysql database for specifically for tests
|
||||
|
||||
## Unit Tests
|
||||
Now you are ready to run the entire test suite from your terminal:
|
||||
|
||||
The application will use values in the `.env.testing` file located
|
||||
in the root directory to override the
|
||||
default settings and/or other values that exist in your `.env` files.
|
||||
`php artisan test`
|
||||
|
||||
Make sure to modify the section in `.env.testing` that has the
|
||||
database settings. In the example below, it is connecting to the
|
||||
[MariaDB](link-to-maria-db) server that is used if you install the
|
||||
application using [Docker](https://docker.com).
|
||||
To run individual test files, you can pass the path to the test that you want to run:
|
||||
|
||||
```dotenv
|
||||
# --------------------------------------------
|
||||
# REQUIRED: DATABASE SETTINGS
|
||||
# --------------------------------------------
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_DATABASE=snipeit
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=changeme1234
|
||||
```
|
||||
|
||||
To run the entire unit test suite, use the following command from your terminal:
|
||||
|
||||
`php artisan test --env=testing`
|
||||
|
||||
To run individual test files, you can pass the path to the test that
|
||||
you want to run.
|
||||
|
||||
`php artisan test --env=testing tests/Unit/AccessoryTest.php`
|
||||
`php artisan test tests/Unit/AccessoryTest.php`
|
||||
|
||||
## Browser Tests
|
||||
|
||||
|
@ -52,11 +30,9 @@ Before attempting to run Dusk tests copy the example environment file for Dusk a
|
|||
|
||||
**Important**: Dusk tests cannot be run using an in-memory SQLite database. Additionally, the Dusk test suite uses the `DatabaseMigrations` trait which will leave the database in a fresh state after running. Therefore, it is recommended that you create a test database and point `DB_DATABASE` in `.env.dusk.local` to it.
|
||||
|
||||
### Test Setup
|
||||
### Running Browser Tests
|
||||
|
||||
Your application needs to be configured and up and running in order for the browser
|
||||
tests to actually run. When running the tests locally, you can start the application
|
||||
using the following command:
|
||||
Your application needs to be configured and up and running in order for the browser tests to actually run. When running the tests locally, you can start the application using the following command:
|
||||
|
||||
`php artisan serve`
|
||||
|
||||
|
|
|
@ -24,10 +24,50 @@ class CategoriesController extends Controller
|
|||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', Category::class);
|
||||
$allowed_columns = ['id', 'name', 'category_type', 'category_type', 'use_default_eula', 'eula_text', 'require_acceptance', 'checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count', 'licenses_count', 'image'];
|
||||
$allowed_columns = [
|
||||
'id',
|
||||
'name',
|
||||
'category_type',
|
||||
'category_type',
|
||||
'use_default_eula',
|
||||
'eula_text',
|
||||
'require_acceptance',
|
||||
'checkin_email',
|
||||
'assets_count',
|
||||
'accessories_count',
|
||||
'consumables_count',
|
||||
'components_count',
|
||||
'licenses_count',
|
||||
'image',
|
||||
];
|
||||
|
||||
$categories = Category::select([
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'name', 'category_type',
|
||||
'use_default_eula',
|
||||
'eula_text',
|
||||
'require_acceptance',
|
||||
'checkin_email',
|
||||
'image'
|
||||
])->withCount('accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count');
|
||||
|
||||
|
||||
/*
|
||||
* This checks to see if we should override the Admin Setting to show archived assets in list.
|
||||
* We don't currently use it within the Snipe-IT GUI, but will be useful for API integrations where they
|
||||
* may actually need to fetch assets that are archived.
|
||||
*
|
||||
* @see \App\Models\Category::showableAssets()
|
||||
*/
|
||||
if ($request->input('archived')=='true') {
|
||||
$categories = $categories->withCount('assets as assets_count');
|
||||
} else {
|
||||
$categories = $categories->withCount('showableAssets as assets_count');
|
||||
}
|
||||
|
||||
|
||||
$categories = Category::select(['id', 'created_at', 'updated_at', 'name', 'category_type', 'use_default_eula', 'eula_text', 'require_acceptance', 'checkin_email', 'image'])
|
||||
->withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count');
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$categories = $categories->TextSearch($request->input('search'));
|
||||
|
|
|
@ -194,7 +194,25 @@ class Category extends SnipeModel
|
|||
*/
|
||||
public function assets()
|
||||
{
|
||||
return $this->hasManyThrough(\App\Models\Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id');
|
||||
return $this->hasManyThrough(Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the category -> assets relationship but also takes into consideration
|
||||
* the setting to show archived in lists.
|
||||
*
|
||||
* We could have complicated the assets() method above, but keeping this separate
|
||||
* should give us more flexibility if we need to return actually archived assets
|
||||
* by their category.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v6.1.0]
|
||||
* @see \App\Models\Asset::scopeAssetsForShow()
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function showableAssets()
|
||||
{
|
||||
return $this->hasManyThrough(Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id')->AssetsForShow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,8 +38,8 @@ class AssetFactory extends Factory
|
|||
{
|
||||
return [
|
||||
'name' => null,
|
||||
'rtd_location_id' => Location::all()->random()->id,
|
||||
'serial' => $this->faker->uuid,
|
||||
'rtd_location_id' => Location::factory(),
|
||||
'serial' => $this->faker->uuid(),
|
||||
'status_id' => 1,
|
||||
'user_id' => 1,
|
||||
'asset_tag' => $this->faker->unixTime('now'),
|
||||
|
@ -47,7 +47,7 @@ class AssetFactory extends Factory
|
|||
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
|
||||
'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'),
|
||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||
'supplier_id' => Supplier::all()->random()->id,
|
||||
'supplier_id' => Supplier::factory(),
|
||||
'requestable' => $this->faker->boolean(),
|
||||
'assigned_to' => null,
|
||||
'assigned_type' => null,
|
||||
|
|
|
@ -39,18 +39,18 @@ class SupplierFactory extends Factory
|
|||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->company,
|
||||
'address' => $this->faker->streetAddress,
|
||||
'address2' => $this->faker->secondaryAddress,
|
||||
'city' => $this->faker->city,
|
||||
'state' => $this->faker->stateAbbr,
|
||||
'zip' => $this->faker->postCode,
|
||||
'country' => $this->faker->countryCode,
|
||||
'contact' => $this->faker->name,
|
||||
'phone' => $this->faker->phoneNumber,
|
||||
'fax' => $this->faker->phoneNumber,
|
||||
'email' => $this->faker->safeEmail,
|
||||
'url' => $this->faker->url,
|
||||
'name' => $this->faker->company(),
|
||||
'address' => $this->faker->streetAddress(),
|
||||
'address2' => $this->faker->secondaryAddress(),
|
||||
'city' => $this->faker->city(),
|
||||
'state' => $this->faker->stateAbbr(),
|
||||
'zip' => $this->faker->postCode(),
|
||||
'country' => $this->faker->countryCode(),
|
||||
'contact' => $this->faker->name(),
|
||||
'phone' => $this->faker->phoneNumber(),
|
||||
'fax' => $this->faker->phoneNumber(),
|
||||
'email' => $this->faker->safeEmail(),
|
||||
'url' => $this->faker->url(),
|
||||
'notes' => $this->faker->text(191), // Supplier notes can be a max of 255 characters.
|
||||
];
|
||||
}
|
||||
|
|
28
phpunit.xml
28
phpunit.xml
|
@ -1,22 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="bootstrap/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="bootstrap/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||
>
|
||||
<coverage>
|
||||
<include>
|
||||
<directory suffix=".php">app/</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Application Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Feature">
|
||||
<directory suffix="Test.php">./tests/Feature</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<env name="APP_ENV" value="testing-ci"/>
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
<env name="BCRYPT_ROUNDS" value="4"/>
|
||||
<env name="CACHE_DRIVER" value="array"/>
|
||||
<env name="SESSION_DRIVER" value="array"/>
|
||||
<env name="MAIL_DRIVER" value="array"/>
|
||||
<env name="QUEUE_DRIVER" value="sync"/>
|
||||
<env name="DB_CONNECTION" value="sqlite"/>
|
||||
<server name="SERVER_NAME" value="http://127.0.0.1:8000"/>
|
||||
<env name="SESSION_DRIVER" value="array"/>
|
||||
<ini name="display_errors" value="true"/>
|
||||
</php>
|
||||
</phpunit>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<li class="active">
|
||||
<a href="#items" data-toggle="tab" title="{{ trans('general.items') }}"> {{ ucwords($category_type_route) }}
|
||||
@if ($category->category_type=='asset')
|
||||
<badge class="badge badge-secondary"> {{ $category->assets()->AssetsForShow()->count() }}</badge>
|
||||
<badge class="badge badge-secondary"> {{ $category->showableAssets()->count() }}</badge>
|
||||
@endif
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -274,7 +274,7 @@
|
|||
</div> <!--/row-->
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<!-- Categories -->
|
||||
<!-- Locations -->
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h2 class="box-title">{{ trans('general.asset') }} {{ trans('general.locations') }}</h2>
|
||||
|
|
|
@ -358,7 +358,7 @@
|
|||
</strong>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{{ $license->reassignable ? 'Yes' : 'No' }}
|
||||
{!! $license->reassignable ? '<i class="fas fa-check text-success" aria-hidden="true"></i> '.trans('general.yes') : '<i class="fas fa-times text-danger" aria-hidden="true"></i> '.trans('general.no') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -5,15 +5,12 @@ namespace Tests\Feature\Api\Users;
|
|||
use App\Models\Company;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Laravel\Passport\Passport;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UsersForSelectListTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function testUsersAreReturned()
|
||||
{
|
||||
Setting::factory()->create();
|
||||
|
|
|
@ -2,17 +2,26 @@
|
|||
|
||||
namespace Tests;
|
||||
|
||||
use App\Http\Middleware\SecurityHeaders;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
use LazilyRefreshDatabase;
|
||||
|
||||
private array $globallyDisabledMiddleware = [
|
||||
SecurityHeaders::class,
|
||||
];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->beforeApplicationDestroyed(fn() => Setting::$_cache = null);
|
||||
|
||||
$this->withoutMiddleware($this->globallyDisabledMiddleware);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,20 +6,10 @@ use App\Models\Manufacturer;
|
|||
use App\Models\Location;
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AccessoryTest extends BaseTest
|
||||
class AccessoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
|
||||
public function testAnAccessoryBelongsToACompany()
|
||||
{
|
||||
$accessory = Accessory::factory()
|
||||
|
@ -57,12 +47,10 @@ class AccessoryTest extends BaseTest
|
|||
|
||||
public function testAnAccessoryHasAManufacturer()
|
||||
{
|
||||
$this->createValidManufacturer('apple');
|
||||
$this->createValidCategory('accessory-keyboard-category');
|
||||
$accessory = Accessory::factory()->appleBtKeyboard()->create(
|
||||
[
|
||||
'category_id' => Category::factory()->create(),
|
||||
'category_id' => Manufacturer::factory()->apple()->create()
|
||||
'manufacturer_id' => Manufacturer::factory()->apple()->create()
|
||||
]);
|
||||
$this->assertInstanceOf(Manufacturer::class, $accessory->manufacturer);
|
||||
}
|
||||
|
|
|
@ -2,20 +2,12 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\AssetMaintenance;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssetMaintenanceTest extends BaseTest
|
||||
class AssetMaintenanceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_zeros_out_warranty_if_blank()
|
||||
public function testZerosOutWarrantyIfBlank()
|
||||
{
|
||||
$c = new AssetMaintenance;
|
||||
$c->is_warranty = '';
|
||||
|
@ -24,10 +16,7 @@ class AssetMaintenanceTest extends BaseTest
|
|||
$this->assertTrue($c->is_warranty == 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_sets_costs_appropriately()
|
||||
public function testSetsCostsAppropriately()
|
||||
{
|
||||
$c = new AssetMaintenance();
|
||||
$c->cost = '0.00';
|
||||
|
@ -38,10 +27,7 @@ class AssetMaintenanceTest extends BaseTest
|
|||
$this->assertTrue($c->cost === 9.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_nulls_out_notes_if_blank()
|
||||
public function testNullsOutNotesIfBlank()
|
||||
{
|
||||
$c = new AssetMaintenance;
|
||||
$c->notes = '';
|
||||
|
@ -50,10 +36,7 @@ class AssetMaintenanceTest extends BaseTest
|
|||
$this->assertTrue($c->notes === 'This is a long note');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_nulls_out_completion_date_if_blank_or_invalid()
|
||||
public function testNullsOutCompletionDateIfBlankOrInvalid()
|
||||
{
|
||||
$c = new AssetMaintenance;
|
||||
$c->completion_date = '';
|
||||
|
|
|
@ -4,18 +4,10 @@ namespace Tests\Unit;
|
|||
use App\Models\Asset;
|
||||
use App\Models\Category;
|
||||
use App\Models\AssetModel;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssetModelTest extends BaseTest
|
||||
class AssetModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testAnAssetModelZerosOutBlankEols()
|
||||
{
|
||||
$am = new AssetModel;
|
||||
|
@ -42,6 +34,4 @@ class AssetModelTest extends BaseTest
|
|||
);
|
||||
$this->assertEquals(1, $model->assets()->count());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,28 +1,14 @@
|
|||
<?php
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Exceptions\CheckoutNotAllowed;
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Company;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use App\Models\Category;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use App\Models\Component;
|
||||
use App\Models\ActionLog;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
class AssetTest extends BaseTest
|
||||
class AssetTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
// public function testAutoIncrementMixed()
|
||||
// {
|
||||
// $expected = '123411';
|
||||
|
@ -41,10 +27,6 @@ class AssetTest extends BaseTest
|
|||
// $this->assertEquals($expected, $next);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testWarrantyExpiresAttribute()
|
||||
{
|
||||
|
||||
|
@ -66,5 +48,4 @@ class AssetTest extends BaseTest
|
|||
$this->assertEquals(Carbon::createFromDate(2019, 1, 1)->format('Y-m-d'), $asset->warranty_expires->format('Y-m-d'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\TestCase;
|
||||
use Auth;
|
||||
use Artisan;
|
||||
|
||||
class BaseTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
Artisan::call('migrate');
|
||||
Setting::factory()->create();
|
||||
}
|
||||
|
||||
protected function signIn($user = null)
|
||||
{
|
||||
if (! $user) {
|
||||
$user = User::factory()->superuser()->create([
|
||||
'location_id' => $this->createValidLocation()->id,
|
||||
]);
|
||||
}
|
||||
Auth::login($user);
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function createValidAssetModel()
|
||||
{
|
||||
return \App\Models\AssetModel::factory()->create([
|
||||
'category_id' => $this->createValidCategory(),
|
||||
'manufacturer_id' => $this->createValidManufacturer(),
|
||||
'depreciation_id' => $this->createValidDepreciation(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createValidCategory()
|
||||
{
|
||||
return \App\Models\Category::factory()->make();
|
||||
}
|
||||
|
||||
protected function createValidCompany()
|
||||
{
|
||||
return \App\Models\Company::factory()->create();
|
||||
}
|
||||
|
||||
protected function createValidDepartment($state = 'engineering', $overrides = [])
|
||||
{
|
||||
return \App\Models\Department::factory()->create(array_merge([
|
||||
'location_id' => $this->createValidLocation()->id,
|
||||
], $overrides));
|
||||
}
|
||||
|
||||
protected function createValidDepreciation()
|
||||
{
|
||||
return \App\Models\Depreciation::factory()->create();
|
||||
}
|
||||
|
||||
protected function createValidLocation($overrides = [])
|
||||
{
|
||||
return \App\Models\Location::factory()->create($overrides);
|
||||
}
|
||||
|
||||
protected function createValidManufacturer()
|
||||
{
|
||||
return \App\Models\Manufacturer::factory()->create();
|
||||
}
|
||||
|
||||
protected function createValidSupplier($overrides = [])
|
||||
{
|
||||
return \App\Models\Supplier::factory()->create($overrides);
|
||||
}
|
||||
|
||||
protected function createValidStatuslabel($state = 'rtd', $overrides = [])
|
||||
{
|
||||
return \App\Models\Statuslabel::factory()->state()->create($overrides);
|
||||
}
|
||||
|
||||
protected function createValidUser($overrides = [])
|
||||
{
|
||||
return \App\Models\User::factory()->create(
|
||||
array_merge([
|
||||
'location_id'=>$this->createValidLocation()->id,
|
||||
], $overrides)
|
||||
);
|
||||
}
|
||||
|
||||
protected function createValidAsset($overrides = [])
|
||||
{
|
||||
$locId = $this->createValidLocation()->id;
|
||||
$this->createValidAssetModel();
|
||||
|
||||
return \App\Models\Asset::factory()->laptopMbp()->create(
|
||||
array_merge([
|
||||
'rtd_location_id' => $locId,
|
||||
'location_id' => $locId,
|
||||
'supplier_id' => $this->createValidSupplier()->id,
|
||||
], $overrides)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,21 +2,12 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Accessory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CategoryTest extends BaseTest
|
||||
class CategoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testFailsEmptyValidation()
|
||||
{
|
||||
// An Asset requires a name, a qty, and a category_id.
|
||||
|
|
|
@ -2,23 +2,11 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Company;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use App\Models\Component;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CompanyTest extends BaseTest
|
||||
class CompanyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function testACompanyCanHaveUsers()
|
||||
{
|
||||
$company = Company::factory()->create();
|
||||
|
|
|
@ -5,20 +5,10 @@ use App\Models\Category;
|
|||
use App\Models\Company;
|
||||
use App\Models\Component;
|
||||
use App\Models\Location;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ComponentTest extends BaseTest
|
||||
class ComponentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
|
||||
public function testAComponentBelongsToACompany()
|
||||
{
|
||||
$component = Component::factory()
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Consumable;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
|
||||
class ConsumableTest extends BaseTest
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -2,24 +2,14 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\CustomField;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
/*
|
||||
* Test strings for db column names gathered from
|
||||
* http://www.omniglot.com/language/phrases/hovercraft.htm
|
||||
*/
|
||||
class CustomFieldTest extends BaseTest
|
||||
class CustomFieldTest extends TestCase
|
||||
{
|
||||
protected $tester;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$customfield = new CustomField();
|
||||
}
|
||||
|
||||
public function testFormat()
|
||||
{
|
||||
$customfield = CustomField::factory()->make(['format' => 'IP']);
|
||||
|
|
|
@ -2,23 +2,15 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Depreciation;
|
||||
use Tests\Unit\BaseTest;
|
||||
use App\Models\Category;
|
||||
use App\Models\License;
|
||||
use App\Models\AssetModel;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DepreciationTest extends BaseTest
|
||||
class DepreciationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
|
||||
public function testADepreciationHasModels()
|
||||
{
|
||||
$this->createValidAssetModel();
|
||||
$depreciation = Depreciation::factory()->create();
|
||||
|
||||
AssetModel::factory()
|
||||
|
|
|
@ -13,19 +13,11 @@ use App\Models\Category;
|
|||
use App\Models\CustomField;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ImporterTest extends BaseTest
|
||||
class ImporterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
// protected $tester;
|
||||
|
||||
// public function testDefaultImportAssetWithCustomFields()
|
||||
// {
|
||||
// $this->signIn();
|
||||
|
|
|
@ -2,24 +2,16 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Location;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
class LocationTest extends BaseTest
|
||||
class LocationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testPassesIfNotSelfParent()
|
||||
{
|
||||
$this->createValidLocation(['id' => 10]);
|
||||
|
||||
$a = Location::factory()->make([
|
||||
'name' => 'Test Location',
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'parent_id' => Location::factory()->create(['id' => 10])->id,
|
||||
]);
|
||||
|
||||
$this->assertTrue($a->isValid());
|
||||
|
|
|
@ -8,19 +8,13 @@ use App\Models\Category;
|
|||
use Carbon\Carbon;
|
||||
use App\Notifications\CheckoutAssetNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
class NotificationTest extends BaseTest
|
||||
class NotificationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA()
|
||||
{
|
||||
|
||||
$admin = User::factory()->superuser()->create();
|
||||
$user = User::factory()->create();
|
||||
$asset = Asset::factory()
|
||||
->create(
|
||||
|
@ -30,14 +24,13 @@ class NotificationTest extends BaseTest
|
|||
[
|
||||
'category_id' => Category::factory()->assetLaptopCategory()->id
|
||||
]
|
||||
)->id,
|
||||
)->id,
|
||||
'warranty_months' => 24,
|
||||
'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)
|
||||
'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format('Y-m-d')
|
||||
]);
|
||||
|
||||
//dd($asset);
|
||||
Notification::fake();
|
||||
$asset->checkOut($user, $asset->id);
|
||||
$asset->checkOut($user, $admin->id);
|
||||
Notification::assertSentTo($user, CheckoutAssetNotification::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,9 @@ use App\Models\Component;
|
|||
use App\Models\Consumable;
|
||||
use App\Models\License;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PermissionsTest extends BaseTest
|
||||
class PermissionsTest extends TestCase
|
||||
{
|
||||
// public function _before()
|
||||
// {
|
||||
|
|
|
@ -2,21 +2,11 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\SnipeModel;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SnipeModelTest extends BaseTest
|
||||
class SnipeModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
// tests
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_sets_purchase_dates_appropriately()
|
||||
public function testSetsPurchaseDatesAppropriately()
|
||||
{
|
||||
$c = new SnipeModel;
|
||||
$c->purchase_date = '';
|
||||
|
@ -25,10 +15,7 @@ class SnipeModelTest extends BaseTest
|
|||
$this->assertTrue($c->purchase_date === '2016-03-25 12:35:50');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_sets_purchase_costs_appropriately()
|
||||
public function testSetsPurchaseCostsAppropriately()
|
||||
{
|
||||
$c = new SnipeModel;
|
||||
$c->purchase_cost = '0.00';
|
||||
|
@ -39,10 +26,7 @@ class SnipeModelTest extends BaseTest
|
|||
$this->assertTrue($c->purchase_cost === 9.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_nulls_blank_location_ids_but_not_others()
|
||||
public function testNullsBlankLocationIdsButNotOthers()
|
||||
{
|
||||
$c = new SnipeModel;
|
||||
$c->location_id = '';
|
||||
|
@ -51,10 +35,7 @@ class SnipeModelTest extends BaseTest
|
|||
$this->assertTrue($c->location_id == 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_nulls_blank_categories_but_not_others()
|
||||
public function testNullsBlankCategoriesButNotOthers()
|
||||
{
|
||||
$c = new SnipeModel;
|
||||
$c->category_id = '';
|
||||
|
@ -63,10 +44,7 @@ class SnipeModelTest extends BaseTest
|
|||
$this->assertTrue($c->category_id == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_nulls_blank_suppliers_but_not_others()
|
||||
public function testNullsBlankSuppliersButNotOthers()
|
||||
{
|
||||
$c = new SnipeModel;
|
||||
$c->supplier_id = '';
|
||||
|
@ -75,10 +53,7 @@ class SnipeModelTest extends BaseTest
|
|||
$this->assertTrue($c->supplier_id == 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_nulls_blank_depreciations_but_not_others()
|
||||
public function testNullsBlankDepreciationsButNotOthers()
|
||||
{
|
||||
$c = new SnipeModel;
|
||||
$c->depreciation_id = '';
|
||||
|
@ -87,10 +62,7 @@ class SnipeModelTest extends BaseTest
|
|||
$this->assertTrue($c->depreciation_id == 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_nulls_blank_manufacturers_but_not_others()
|
||||
public function testNullsBlankManufacturersButNotOthers()
|
||||
{
|
||||
$c = new SnipeModel;
|
||||
$c->manufacturer_id = '';
|
||||
|
|
|
@ -2,18 +2,10 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Statuslabel;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StatuslabelTest extends BaseTest
|
||||
class StatuslabelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testRTDStatuslabelAdd()
|
||||
{
|
||||
$statuslabel = Statuslabel::factory()->rtd()->create();
|
||||
|
|
|
@ -2,18 +2,10 @@
|
|||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Tests\Unit\BaseTest;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserTest extends BaseTest
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testFirstNameSplit()
|
||||
{
|
||||
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
||||
|
|
Loading…
Reference in a new issue