-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
349 additions
and
211 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests\Http; | ||
|
||
use Cone\Root\Fields\BelongsToMany; | ||
use Cone\Root\Root; | ||
use Cone\Root\Tests\TestCase; | ||
use Cone\Root\Tests\User; | ||
|
||
class BelongsToManyControllerTest extends TestCase | ||
{ | ||
protected User $admin; | ||
|
||
protected BelongsToMany $field; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->admin = User::factory()->create(); | ||
|
||
$this->field = Root::instance() | ||
->resources | ||
->resolve('users') | ||
->resolveFields($this->app['request']) | ||
->first(function ($field) { | ||
return $field->getModelAttribute() === 'teams'; | ||
}); | ||
} | ||
|
||
public function test_a_belongs_to_many_controller_handles_index(): void | ||
{ | ||
$this->actingAs($this->admin) | ||
->get('/root/users/'.$this->admin->getKey().'/fields/teams') | ||
->assertOk() | ||
->assertViewIs('root::resources.index') | ||
->assertViewHas($this->field->toIndex($this->app['request'], $this->admin)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests; | ||
|
||
use Illuminate\Database\Eloquent\Relations\Pivot as Model; | ||
|
||
class Pivot extends Model | ||
{ | ||
public function save(array $options = []) | ||
{ | ||
$this->setAttribute($this->getKeyName(), $this->getKey()); | ||
|
||
return true; | ||
} | ||
|
||
public function delete() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Team extends Model | ||
{ | ||
protected $guarded = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('teams', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::drop('teams'); | ||
} | ||
}; |
32 changes: 32 additions & 0 deletions
32
tests/migrations/2024_06_14_213755_create_team_user_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use Cone\Root\Tests\Team; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('team_user', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete(); | ||
$table->foreignIdFor(Team::class)->constrained()->cascadeOnDelete(); | ||
$table->string('role'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::drop('team_user'); | ||
} | ||
}; |