Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix committed Feb 22, 2024
1 parent 8d9e1b1 commit cec20c1
Show file tree
Hide file tree
Showing 22 changed files with 830 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\CreateJsonTrait
*/
trait CreateJsonTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\CreateTrait
*/
trait CreateTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\DestroyJsonTrait
*/
trait DestroyJsonTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand All @@ -20,7 +26,7 @@ public function test_json_guest_cannot_destroy()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand Down Expand Up @@ -52,7 +58,7 @@ public function test_json_destroy_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->admin()->create();

Expand Down Expand Up @@ -96,7 +102,7 @@ public function test_json_destroy_as_admin_and_succeed_with_force_delete()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->admin()->create();

Expand Down Expand Up @@ -131,7 +137,7 @@ public function test_json_destroy_as_admin_and_succeed_with_no_content()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->admin()->create();

Expand Down Expand Up @@ -171,7 +177,7 @@ public function test_json_destroy_as_admin_and_succeed_and_ignore_redirect()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->admin()->create();

Expand Down Expand Up @@ -218,7 +224,7 @@ public function test_json_destroy_as_user_and_get_denied_and_no_force_delete_all
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->create();

Expand Down
16 changes: 11 additions & 5 deletions src/Feature/Http/Controllers/Resource/Playground/DestroyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\DestroyTrait
*/
trait DestroyTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand All @@ -20,7 +26,7 @@ public function test_guest_cannot_destroy()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand Down Expand Up @@ -52,7 +58,7 @@ public function test_destroy_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->admin()->create();

Expand Down Expand Up @@ -93,7 +99,7 @@ public function test_destroy_as_admin_and_succeed_with_force_delete()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->admin()->create();

Expand Down Expand Up @@ -128,7 +134,7 @@ public function test_destroy_as_admin_and_succeed_with_redirect_to_index_with_tr
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->admin()->create();

Expand Down Expand Up @@ -175,7 +181,7 @@ public function test_destroy_as_user_and_get_denied_and_no_force_delete_allowed(
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$user = User::factory()->create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\EditJsonTrait
*/
trait EditJsonTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand All @@ -25,7 +31,7 @@ public function test_json_guest_cannot_get_edit_info()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand All @@ -44,7 +50,7 @@ public function test_json_admin_can_get_edit_info()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand Down Expand Up @@ -73,7 +79,7 @@ public function test_json_edit_as_admin_view_rendered_by_user_with_invalid_param
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand Down
14 changes: 10 additions & 4 deletions src/Feature/Http/Controllers/Resource/Playground/EditTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\EditTrait
*/
trait EditTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand All @@ -20,7 +26,7 @@ public function test_guest_cannot_render_edit_view()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand All @@ -40,7 +46,7 @@ public function test_admin_can_render_edit_view()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand All @@ -64,7 +70,7 @@ public function test_admin_can_render_edit_view_with_return_url()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand Down Expand Up @@ -96,7 +102,7 @@ public function test_edit_view_as_admin_with_invalid_parameter_and_fail_validati
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\IndexJsonTrait
*/
trait IndexJsonTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand All @@ -25,13 +31,11 @@ public function test_json_guest_cannot_get_index()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

$url = route($packageInfo['model_route'], [
$packageInfo['model_slug'] => $model->id,
]);
$url = route($packageInfo['model_route']);

$response = $this->getJson($url);
$response->assertStatus(403);
Expand All @@ -41,15 +45,13 @@ public function test_json_admin_can_get_index()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

$user = User::factory()->admin()->create();

$url = route($packageInfo['model_route'], [
$packageInfo['model_slug'] => $model->id,
]);
$url = route($packageInfo['model_route']);

$response = $this->actingAs($user)->getJson($url);

Expand Down
18 changes: 10 additions & 8 deletions src/Feature/Http/Controllers/Resource/Playground/IndexTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/
namespace Playground\Test\Feature\Http\Controllers\Resource\Playground;

use Illuminate\Database\Eloquent\Model;
use Playground\Test\Models\PlaygroundUser as User;

/**
* \Playground\Test\Feature\Http\Controllers\Resource\Playground\IndexTrait
*/
trait IndexTrait
{
/**
* @return class-string<Model>
*/
abstract public function getGetFqdn(): string;

/**
* @return array<string, string>
*/
Expand All @@ -20,13 +26,11 @@ public function test_guest_cannot_render_index_view()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

$url = route($packageInfo['model_route'], [
$packageInfo['model_slug'] => $model->id,
]);
$url = route($packageInfo['model_route']);

$response = $this->get($url);

Expand All @@ -37,15 +41,13 @@ public function test_admin_can_render_index_view()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;
$fqdn = $this->getGetFqdn();

$model = $fqdn::factory()->create();

$user = User::factory()->admin()->create();

$url = route($packageInfo['model_route'], [
$packageInfo['model_slug'] => $model->id,
]);
$url = route($packageInfo['model_route']);

$response = $this->actingAs($user)->get($url);

Expand Down
Loading

0 comments on commit cec20c1

Please sign in to comment.