mirror of https://github.com/kcal-app/kcal.git
Add User CRUD controller tests
This commit is contained in:
parent
a9fad1bff0
commit
0d5b3fe4fc
|
@ -43,6 +43,9 @@ class IngredientAmountFactory extends Factory
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function configure(): static
|
public function configure(): static
|
||||||
{
|
{
|
||||||
return $this->afterMaking(function (IngredientAmount $ingredient_amount) {
|
return $this->afterMaking(function (IngredientAmount $ingredient_amount) {
|
||||||
|
|
|
@ -31,6 +31,9 @@ abstract class HttpControllerTestCase extends LoggedInTestCase
|
||||||
return $this->factory()->create();
|
return $this->factory()->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test instances index.
|
||||||
|
*/
|
||||||
public function testCanLoadIndex(): void
|
public function testCanLoadIndex(): void
|
||||||
{
|
{
|
||||||
$index_url = action([$this->class(), 'index']);
|
$index_url = action([$this->class(), 'index']);
|
||||||
|
@ -38,6 +41,9 @@ abstract class HttpControllerTestCase extends LoggedInTestCase
|
||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test instance add.
|
||||||
|
*/
|
||||||
public function testCanAddInstance(): void
|
public function testCanAddInstance(): void
|
||||||
{
|
{
|
||||||
$create_url = action([$this->class(), 'create']);
|
$create_url = action([$this->class(), 'create']);
|
||||||
|
@ -49,6 +55,9 @@ abstract class HttpControllerTestCase extends LoggedInTestCase
|
||||||
$response->assertSessionHasNoErrors();
|
$response->assertSessionHasNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test instance view.
|
||||||
|
*/
|
||||||
public function testCanViewInstance(): void
|
public function testCanViewInstance(): void
|
||||||
{
|
{
|
||||||
$instance = $this->createInstance();
|
$instance = $this->createInstance();
|
||||||
|
@ -58,6 +67,9 @@ abstract class HttpControllerTestCase extends LoggedInTestCase
|
||||||
$response->assertViewHas($this->routeKey());
|
$response->assertViewHas($this->routeKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test instance edit.
|
||||||
|
*/
|
||||||
public function testCanEditInstance(): void
|
public function testCanEditInstance(): void
|
||||||
{
|
{
|
||||||
$instance = $this->createInstance();
|
$instance = $this->createInstance();
|
||||||
|
@ -71,6 +83,9 @@ abstract class HttpControllerTestCase extends LoggedInTestCase
|
||||||
$response->assertSessionHasNoErrors();
|
$response->assertSessionHasNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test instance delete/destroy.
|
||||||
|
*/
|
||||||
public function testCanDeleteInstance(): void
|
public function testCanDeleteInstance(): void
|
||||||
{
|
{
|
||||||
$instance = $this->createInstance();
|
$instance = $this->createInstance();
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\UserController;
|
||||||
|
use App\Models\User;
|
||||||
|
use Database\Factories\UserFactory;
|
||||||
|
|
||||||
|
class UserControllerTest extends HttpControllerTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function class(): string
|
||||||
|
{
|
||||||
|
return UserController::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function factory(): UserFactory
|
||||||
|
{
|
||||||
|
return User::factory();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function routeKey(): string
|
||||||
|
{
|
||||||
|
return 'user';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @doesNotPerformAssertions
|
||||||
|
*/
|
||||||
|
public function testCanViewInstance(): void
|
||||||
|
{
|
||||||
|
$this->setName('can *not* view instance');
|
||||||
|
// Users are not independently viewable.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function testCanAddInstance(): void
|
||||||
|
{
|
||||||
|
$create_url = action([$this->class(), 'create']);
|
||||||
|
$response = $this->get($create_url);
|
||||||
|
$response->assertOk();
|
||||||
|
$instance = $this->factory()->make();
|
||||||
|
$attributes = $instance->toArray();
|
||||||
|
$attributes['password'] = 'password';
|
||||||
|
$attributes['password_confirmation'] = $attributes['password'];
|
||||||
|
$store_url = action([$this->class(), 'store']);
|
||||||
|
$response = $this->post($store_url, $attributes);
|
||||||
|
$response->assertSessionHasNoErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanNotDeleteSelf(): void {
|
||||||
|
$user = User::first();
|
||||||
|
$edit_url = action([$this->class(), 'delete'], [$this->routeKey() => $user]);
|
||||||
|
$response = $this->get($edit_url);
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue