TRF Certest first commit

This commit is contained in:
2025-02-26 08:57:46 +01:00
commit 3ce064a108
2524 changed files with 475404 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace Tests\Setup;
use Vanguard\Permission;
use Vanguard\Role;
class RoleFactory
{
protected $permissions = [];
protected $removable = false;
public function withPermissions($permissions)
{
$this->permissions = func_get_args();
return $this;
}
public function removable()
{
$this->removable = true;
return $this;
}
public function unremovable()
{
$this->removable = false;
return $this;
}
public function create()
{
$role = Role::factory()->create([
'removable' => $this->removable,
]);
foreach ($this->permissions as $name) {
$role->attachPermission(Permission::where('name', $name)->first());
}
return $role;
}
}
+88
View File
@@ -0,0 +1,88 @@
<?php
namespace Tests\Setup;
use Facades\Tests\Setup\RoleFactory;
use Vanguard\Role;
use Vanguard\Support\Enum\UserStatus;
use Vanguard\User;
class UserFactory
{
protected $params = [];
protected $role;
public function withCredentials($username, $password)
{
$this->params['username'] = $username;
$this->params['password'] = $password;
return $this;
}
public function banned()
{
$this->params['status'] = UserStatus::BANNED;
return $this;
}
public function unconfirmed()
{
$this->params['status'] = UserStatus::UNCONFIRMED;
return $this;
}
public function unverified()
{
$this->params['email_verified_at'] = null;
return $this;
}
public function role(Role $role)
{
$this->role = $role;
return $this;
}
public function admin()
{
return $this->role(Role::where('name', 'Admin')->first());
}
public function user()
{
return $this->role(Role::where('name', 'User')->first());
}
public function email($email)
{
$this->params['email'] = $email;
return $this;
}
public function withPermissions($permissions)
{
$permissions = func_get_args();
$this->role(
RoleFactory::withPermissions($permissions)->create()
);
return $this;
}
public function create(array $overrides = [])
{
if ($this->role) {
$this->params['role_id'] = $this->role;
}
return User::factory()->create(array_merge($this->params, $overrides));
}
}