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
32 changed files with 192 additions and 496 deletions
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
|
||||||
.env.dusk.*
|
.env.dusk.*
|
||||||
!.env.dusk.example
|
!.env.dusk.example
|
||||||
|
.env.testing
|
||||||
phpstan.neon
|
phpstan.neon
|
||||||
.idea
|
.idea
|
||||||
/bin/
|
/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 document is targeted at developers looking to make modifications to this application's code base and want to run the existing test suite.
|
||||||
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,
|
Before attempting to run the test suite copy the example environment file for tests and update the values to match your environment:
|
||||||
making sure to have also run the [database migrations](link to db migrations).
|
|
||||||
|
|
||||||
|
`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
|
`php artisan test`
|
||||||
in the root directory to override the
|
|
||||||
default settings and/or other values that exist in your `.env` files.
|
|
||||||
|
|
||||||
Make sure to modify the section in `.env.testing` that has the
|
To run individual test files, you can pass the path to the test that you want to run:
|
||||||
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).
|
|
||||||
|
|
||||||
```dotenv
|
`php artisan test tests/Unit/AccessoryTest.php`
|
||||||
# --------------------------------------------
|
|
||||||
# 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`
|
|
||||||
|
|
||||||
## Browser Tests
|
## 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.
|
**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
|
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:
|
||||||
tests to actually run. When running the tests locally, you can start the application
|
|
||||||
using the following command:
|
|
||||||
|
|
||||||
`php artisan serve`
|
`php artisan serve`
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,50 @@ class CategoriesController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Category::class);
|
$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')) {
|
if ($request->filled('search')) {
|
||||||
$categories = $categories->TextSearch($request->input('search'));
|
$categories = $categories->TextSearch($request->input('search'));
|
||||||
|
|
|
@ -194,7 +194,25 @@ class Category extends SnipeModel
|
||||||
*/
|
*/
|
||||||
public function assets()
|
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 [
|
return [
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'rtd_location_id' => Location::all()->random()->id,
|
'rtd_location_id' => Location::factory(),
|
||||||
'serial' => $this->faker->uuid,
|
'serial' => $this->faker->uuid(),
|
||||||
'status_id' => 1,
|
'status_id' => 1,
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'asset_tag' => $this->faker->unixTime('now'),
|
'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_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'),
|
'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'),
|
||||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||||
'supplier_id' => Supplier::all()->random()->id,
|
'supplier_id' => Supplier::factory(),
|
||||||
'requestable' => $this->faker->boolean(),
|
'requestable' => $this->faker->boolean(),
|
||||||
'assigned_to' => null,
|
'assigned_to' => null,
|
||||||
'assigned_type' => null,
|
'assigned_type' => null,
|
||||||
|
|
|
@ -39,18 +39,18 @@ class SupplierFactory extends Factory
|
||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => $this->faker->company,
|
'name' => $this->faker->company(),
|
||||||
'address' => $this->faker->streetAddress,
|
'address' => $this->faker->streetAddress(),
|
||||||
'address2' => $this->faker->secondaryAddress,
|
'address2' => $this->faker->secondaryAddress(),
|
||||||
'city' => $this->faker->city,
|
'city' => $this->faker->city(),
|
||||||
'state' => $this->faker->stateAbbr,
|
'state' => $this->faker->stateAbbr(),
|
||||||
'zip' => $this->faker->postCode,
|
'zip' => $this->faker->postCode(),
|
||||||
'country' => $this->faker->countryCode,
|
'country' => $this->faker->countryCode(),
|
||||||
'contact' => $this->faker->name,
|
'contact' => $this->faker->name(),
|
||||||
'phone' => $this->faker->phoneNumber,
|
'phone' => $this->faker->phoneNumber(),
|
||||||
'fax' => $this->faker->phoneNumber,
|
'fax' => $this->faker->phoneNumber(),
|
||||||
'email' => $this->faker->safeEmail,
|
'email' => $this->faker->safeEmail(),
|
||||||
'url' => $this->faker->url,
|
'url' => $this->faker->url(),
|
||||||
'notes' => $this->faker->text(191), // Supplier notes can be a max of 255 characters.
|
'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"?>
|
<?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>
|
<coverage>
|
||||||
<include>
|
<include>
|
||||||
<directory suffix=".php">app/</directory>
|
<directory suffix=".php">app/</directory>
|
||||||
</include>
|
</include>
|
||||||
</coverage>
|
</coverage>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Application Test Suite">
|
<testsuite name="Unit">
|
||||||
<directory>./tests/</directory>
|
<directory suffix="Test.php">./tests/Unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="Feature">
|
||||||
|
<directory suffix="Test.php">./tests/Feature</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<php>
|
<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="CACHE_DRIVER" value="array"/>
|
||||||
<env name="SESSION_DRIVER" value="array"/>
|
<env name="MAIL_DRIVER" value="array"/>
|
||||||
<env name="QUEUE_DRIVER" value="sync"/>
|
<env name="QUEUE_DRIVER" value="sync"/>
|
||||||
<env name="DB_CONNECTION" value="sqlite"/>
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
<server name="SERVER_NAME" value="http://127.0.0.1:8000"/>
|
|
||||||
<ini name="display_errors" value="true"/>
|
<ini name="display_errors" value="true"/>
|
||||||
</php>
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<li class="active">
|
<li class="active">
|
||||||
<a href="#items" data-toggle="tab" title="{{ trans('general.items') }}"> {{ ucwords($category_type_route) }}
|
<a href="#items" data-toggle="tab" title="{{ trans('general.items') }}"> {{ ucwords($category_type_route) }}
|
||||||
@if ($category->category_type=='asset')
|
@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
|
@endif
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -274,7 +274,7 @@
|
||||||
</div> <!--/row-->
|
</div> <!--/row-->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<!-- Categories -->
|
<!-- Locations -->
|
||||||
<div class="box box-default">
|
<div class="box box-default">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h2 class="box-title">{{ trans('general.asset') }} {{ trans('general.locations') }}</h2>
|
<h2 class="box-title">{{ trans('general.asset') }} {{ trans('general.locations') }}</h2>
|
||||||
|
|
|
@ -358,7 +358,7 @@
|
||||||
</strong>
|
</strong>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-9">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,12 @@ namespace Tests\Feature\Api\Users;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Testing\Fluent\AssertableJson;
|
use Illuminate\Testing\Fluent\AssertableJson;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UsersForSelectListTest extends TestCase
|
class UsersForSelectListTest extends TestCase
|
||||||
{
|
{
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function testUsersAreReturned()
|
public function testUsersAreReturned()
|
||||||
{
|
{
|
||||||
Setting::factory()->create();
|
Setting::factory()->create();
|
||||||
|
|
|
@ -2,17 +2,26 @@
|
||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
|
use App\Http\Middleware\SecurityHeaders;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
use CreatesApplication;
|
use CreatesApplication;
|
||||||
|
use LazilyRefreshDatabase;
|
||||||
|
|
||||||
|
private array $globallyDisabledMiddleware = [
|
||||||
|
SecurityHeaders::class,
|
||||||
|
];
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->beforeApplicationDestroyed(fn() => Setting::$_cache = null);
|
$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\Location;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
|
|
||||||
class AccessoryTest extends BaseTest
|
class AccessoryTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testAnAccessoryBelongsToACompany()
|
public function testAnAccessoryBelongsToACompany()
|
||||||
{
|
{
|
||||||
$accessory = Accessory::factory()
|
$accessory = Accessory::factory()
|
||||||
|
@ -57,12 +47,10 @@ class AccessoryTest extends BaseTest
|
||||||
|
|
||||||
public function testAnAccessoryHasAManufacturer()
|
public function testAnAccessoryHasAManufacturer()
|
||||||
{
|
{
|
||||||
$this->createValidManufacturer('apple');
|
|
||||||
$this->createValidCategory('accessory-keyboard-category');
|
|
||||||
$accessory = Accessory::factory()->appleBtKeyboard()->create(
|
$accessory = Accessory::factory()->appleBtKeyboard()->create(
|
||||||
[
|
[
|
||||||
'category_id' => Category::factory()->create(),
|
'category_id' => Category::factory()->create(),
|
||||||
'category_id' => Manufacturer::factory()->apple()->create()
|
'manufacturer_id' => Manufacturer::factory()->apple()->create()
|
||||||
]);
|
]);
|
||||||
$this->assertInstanceOf(Manufacturer::class, $accessory->manufacturer);
|
$this->assertInstanceOf(Manufacturer::class, $accessory->manufacturer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,12 @@
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\AssetMaintenance;
|
use App\Models\AssetMaintenance;
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AssetMaintenanceTest extends BaseTest
|
class AssetMaintenanceTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
public function testZerosOutWarrantyIfBlank()
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_zeros_out_warranty_if_blank()
|
|
||||||
{
|
{
|
||||||
$c = new AssetMaintenance;
|
$c = new AssetMaintenance;
|
||||||
$c->is_warranty = '';
|
$c->is_warranty = '';
|
||||||
|
@ -24,10 +16,7 @@ class AssetMaintenanceTest extends BaseTest
|
||||||
$this->assertTrue($c->is_warranty == 4);
|
$this->assertTrue($c->is_warranty == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testSetsCostsAppropriately()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_sets_costs_appropriately()
|
|
||||||
{
|
{
|
||||||
$c = new AssetMaintenance();
|
$c = new AssetMaintenance();
|
||||||
$c->cost = '0.00';
|
$c->cost = '0.00';
|
||||||
|
@ -38,10 +27,7 @@ class AssetMaintenanceTest extends BaseTest
|
||||||
$this->assertTrue($c->cost === 9.5);
|
$this->assertTrue($c->cost === 9.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testNullsOutNotesIfBlank()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_nulls_out_notes_if_blank()
|
|
||||||
{
|
{
|
||||||
$c = new AssetMaintenance;
|
$c = new AssetMaintenance;
|
||||||
$c->notes = '';
|
$c->notes = '';
|
||||||
|
@ -50,10 +36,7 @@ class AssetMaintenanceTest extends BaseTest
|
||||||
$this->assertTrue($c->notes === 'This is a long note');
|
$this->assertTrue($c->notes === 'This is a long note');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testNullsOutCompletionDateIfBlankOrInvalid()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_nulls_out_completion_date_if_blank_or_invalid()
|
|
||||||
{
|
{
|
||||||
$c = new AssetMaintenance;
|
$c = new AssetMaintenance;
|
||||||
$c->completion_date = '';
|
$c->completion_date = '';
|
||||||
|
|
|
@ -4,18 +4,10 @@ namespace Tests\Unit;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
|
|
||||||
class AssetModelTest extends BaseTest
|
class AssetModelTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
public function testAnAssetModelZerosOutBlankEols()
|
public function testAnAssetModelZerosOutBlankEols()
|
||||||
{
|
{
|
||||||
$am = new AssetModel;
|
$am = new AssetModel;
|
||||||
|
@ -42,6 +34,4 @@ class AssetModelTest extends BaseTest
|
||||||
);
|
);
|
||||||
$this->assertEquals(1, $model->assets()->count());
|
$this->assertEquals(1, $model->assets()->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Exceptions\CheckoutNotAllowed;
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
use App\Models\Company;
|
|
||||||
use App\Models\Location;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
use App\Models\Component;
|
|
||||||
use App\Models\ActionLog;
|
|
||||||
|
|
||||||
|
class AssetTest extends TestCase
|
||||||
class AssetTest extends BaseTest
|
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
// public function testAutoIncrementMixed()
|
// public function testAutoIncrementMixed()
|
||||||
// {
|
// {
|
||||||
// $expected = '123411';
|
// $expected = '123411';
|
||||||
|
@ -41,10 +27,6 @@ class AssetTest extends BaseTest
|
||||||
// $this->assertEquals($expected, $next);
|
// $this->assertEquals($expected, $next);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testWarrantyExpiresAttribute()
|
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'));
|
$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;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\Category;
|
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\AssetModel;
|
||||||
use App\Models\Asset;
|
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()
|
public function testFailsEmptyValidation()
|
||||||
{
|
{
|
||||||
// An Asset requires a name, a qty, and a category_id.
|
// An Asset requires a name, a qty, and a category_id.
|
||||||
|
|
|
@ -2,23 +2,11 @@
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\Company;
|
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 App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
class CompanyTest extends BaseTest
|
class CompanyTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
|
|
||||||
public function testACompanyCanHaveUsers()
|
public function testACompanyCanHaveUsers()
|
||||||
{
|
{
|
||||||
$company = Company::factory()->create();
|
$company = Company::factory()->create();
|
||||||
|
|
|
@ -5,20 +5,10 @@ use App\Models\Category;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Component;
|
use App\Models\Component;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
|
|
||||||
class ComponentTest extends BaseTest
|
class ComponentTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testAComponentBelongsToACompany()
|
public function testAComponentBelongsToACompany()
|
||||||
{
|
{
|
||||||
$component = Component::factory()
|
$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;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test strings for db column names gathered from
|
* Test strings for db column names gathered from
|
||||||
* http://www.omniglot.com/language/phrases/hovercraft.htm
|
* 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()
|
public function testFormat()
|
||||||
{
|
{
|
||||||
$customfield = CustomField::factory()->make(['format' => 'IP']);
|
$customfield = CustomField::factory()->make(['format' => 'IP']);
|
||||||
|
|
|
@ -2,23 +2,15 @@
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\Depreciation;
|
use App\Models\Depreciation;
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
class DepreciationTest extends BaseTest
|
class DepreciationTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testADepreciationHasModels()
|
public function testADepreciationHasModels()
|
||||||
{
|
{
|
||||||
$this->createValidAssetModel();
|
|
||||||
$depreciation = Depreciation::factory()->create();
|
$depreciation = Depreciation::factory()->create();
|
||||||
|
|
||||||
AssetModel::factory()
|
AssetModel::factory()
|
||||||
|
|
|
@ -13,19 +13,11 @@ use App\Models\Category;
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Models\User;
|
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 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()
|
// public function testDefaultImportAssetWithCustomFields()
|
||||||
// {
|
// {
|
||||||
// $this->signIn();
|
// $this->signIn();
|
||||||
|
|
|
@ -2,24 +2,16 @@
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use Tests\Unit\BaseTest;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class LocationTest extends TestCase
|
||||||
class LocationTest extends BaseTest
|
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
public function testPassesIfNotSelfParent()
|
public function testPassesIfNotSelfParent()
|
||||||
{
|
{
|
||||||
$this->createValidLocation(['id' => 10]);
|
|
||||||
|
|
||||||
$a = Location::factory()->make([
|
$a = Location::factory()->make([
|
||||||
'name' => 'Test Location',
|
'name' => 'Test Location',
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'parent_id' => 10,
|
'parent_id' => Location::factory()->create(['id' => 10])->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertTrue($a->isValid());
|
$this->assertTrue($a->isValid());
|
||||||
|
|
|
@ -8,19 +8,13 @@ use App\Models\Category;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use App\Notifications\CheckoutAssetNotification;
|
use App\Notifications\CheckoutAssetNotification;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Tests\Unit\BaseTest;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class NotificationTest extends TestCase
|
||||||
class NotificationTest extends BaseTest
|
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA()
|
public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA()
|
||||||
{
|
{
|
||||||
|
$admin = User::factory()->superuser()->create();
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$asset = Asset::factory()
|
$asset = Asset::factory()
|
||||||
->create(
|
->create(
|
||||||
|
@ -30,14 +24,13 @@ class NotificationTest extends BaseTest
|
||||||
[
|
[
|
||||||
'category_id' => Category::factory()->assetLaptopCategory()->id
|
'category_id' => Category::factory()->assetLaptopCategory()->id
|
||||||
]
|
]
|
||||||
)->id,
|
)->id,
|
||||||
'warranty_months' => 24,
|
'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();
|
Notification::fake();
|
||||||
$asset->checkOut($user, $asset->id);
|
$asset->checkOut($user, $admin->id);
|
||||||
Notification::assertSentTo($user, CheckoutAssetNotification::class);
|
Notification::assertSentTo($user, CheckoutAssetNotification::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,9 @@ use App\Models\Component;
|
||||||
use App\Models\Consumable;
|
use App\Models\Consumable;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
|
|
||||||
class PermissionsTest extends BaseTest
|
class PermissionsTest extends TestCase
|
||||||
{
|
{
|
||||||
// public function _before()
|
// public function _before()
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -2,21 +2,11 @@
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\SnipeModel;
|
use App\Models\SnipeModel;
|
||||||
use Tests\Unit\BaseTest;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class SnipeModelTest extends BaseTest
|
class SnipeModelTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
public function testSetsPurchaseDatesAppropriately()
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
// tests
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_sets_purchase_dates_appropriately()
|
|
||||||
{
|
{
|
||||||
$c = new SnipeModel;
|
$c = new SnipeModel;
|
||||||
$c->purchase_date = '';
|
$c->purchase_date = '';
|
||||||
|
@ -25,10 +15,7 @@ class SnipeModelTest extends BaseTest
|
||||||
$this->assertTrue($c->purchase_date === '2016-03-25 12:35:50');
|
$this->assertTrue($c->purchase_date === '2016-03-25 12:35:50');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testSetsPurchaseCostsAppropriately()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_sets_purchase_costs_appropriately()
|
|
||||||
{
|
{
|
||||||
$c = new SnipeModel;
|
$c = new SnipeModel;
|
||||||
$c->purchase_cost = '0.00';
|
$c->purchase_cost = '0.00';
|
||||||
|
@ -39,10 +26,7 @@ class SnipeModelTest extends BaseTest
|
||||||
$this->assertTrue($c->purchase_cost === 9.5);
|
$this->assertTrue($c->purchase_cost === 9.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testNullsBlankLocationIdsButNotOthers()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_nulls_blank_location_ids_but_not_others()
|
|
||||||
{
|
{
|
||||||
$c = new SnipeModel;
|
$c = new SnipeModel;
|
||||||
$c->location_id = '';
|
$c->location_id = '';
|
||||||
|
@ -51,10 +35,7 @@ class SnipeModelTest extends BaseTest
|
||||||
$this->assertTrue($c->location_id == 5);
|
$this->assertTrue($c->location_id == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testNullsBlankCategoriesButNotOthers()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_nulls_blank_categories_but_not_others()
|
|
||||||
{
|
{
|
||||||
$c = new SnipeModel;
|
$c = new SnipeModel;
|
||||||
$c->category_id = '';
|
$c->category_id = '';
|
||||||
|
@ -63,10 +44,7 @@ class SnipeModelTest extends BaseTest
|
||||||
$this->assertTrue($c->category_id == 1);
|
$this->assertTrue($c->category_id == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testNullsBlankSuppliersButNotOthers()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_nulls_blank_suppliers_but_not_others()
|
|
||||||
{
|
{
|
||||||
$c = new SnipeModel;
|
$c = new SnipeModel;
|
||||||
$c->supplier_id = '';
|
$c->supplier_id = '';
|
||||||
|
@ -75,10 +53,7 @@ class SnipeModelTest extends BaseTest
|
||||||
$this->assertTrue($c->supplier_id == 4);
|
$this->assertTrue($c->supplier_id == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testNullsBlankDepreciationsButNotOthers()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_nulls_blank_depreciations_but_not_others()
|
|
||||||
{
|
{
|
||||||
$c = new SnipeModel;
|
$c = new SnipeModel;
|
||||||
$c->depreciation_id = '';
|
$c->depreciation_id = '';
|
||||||
|
@ -87,10 +62,7 @@ class SnipeModelTest extends BaseTest
|
||||||
$this->assertTrue($c->depreciation_id == 4);
|
$this->assertTrue($c->depreciation_id == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testNullsBlankManufacturersButNotOthers()
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function it_nulls_blank_manufacturers_but_not_others()
|
|
||||||
{
|
{
|
||||||
$c = new SnipeModel;
|
$c = new SnipeModel;
|
||||||
$c->manufacturer_id = '';
|
$c->manufacturer_id = '';
|
||||||
|
|
|
@ -2,18 +2,10 @@
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\Statuslabel;
|
use App\Models\Statuslabel;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
|
|
||||||
class StatuslabelTest extends BaseTest
|
class StatuslabelTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
public function testRTDStatuslabelAdd()
|
public function testRTDStatuslabelAdd()
|
||||||
{
|
{
|
||||||
$statuslabel = Statuslabel::factory()->rtd()->create();
|
$statuslabel = Statuslabel::factory()->rtd()->create();
|
||||||
|
|
|
@ -2,18 +2,10 @@
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Tests\TestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Tests\Unit\BaseTest;
|
|
||||||
|
|
||||||
class UserTest extends BaseTest
|
class UserTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \UnitTester
|
|
||||||
*/
|
|
||||||
protected $tester;
|
|
||||||
|
|
||||||
public function testFirstNameSplit()
|
public function testFirstNameSplit()
|
||||||
{
|
{
|
||||||
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
||||||
|
|
Loading…
Add table
Reference in a new issue