mirror of https://github.com/kcal-app/kcal.git
Add media to User Controller test instances
This commit is contained in:
parent
03f7319157
commit
1d1df92d8f
|
@ -4,7 +4,9 @@ namespace Database\Factories;
|
|||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UserFactory extends Factory
|
||||
|
@ -35,4 +37,20 @@ class UserFactory extends Factory
|
|||
{
|
||||
return $this->state(['admin' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user and add fake media to it.
|
||||
*/
|
||||
public function createOneWithMedia(array $attributes = []): User {
|
||||
Storage::fake('tests');
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $this->createOne($attributes);
|
||||
$file = UploadedFile::fake()->image('user.jpg', 400, 400);
|
||||
$path = $file->store('tests');
|
||||
$user->addMediaFromDisk($path)
|
||||
->usingName($user->name)
|
||||
->usingFileName("{$user->slug}.jpg")
|
||||
->toMediaCollection();
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,14 @@ class UserControllerTest extends HttpControllerTestCase
|
|||
return 'user';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function createInstance(): User
|
||||
{
|
||||
return $this->factory()->createOneWithMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
|
|
|
@ -32,7 +32,7 @@ trait LogsIn
|
|||
$this->user = User::factory()
|
||||
->hasGoals(2)
|
||||
->hasJournalEntries(5)
|
||||
->create(['admin' => false]);
|
||||
->createOneWithMedia(['admin' => false]);
|
||||
$this->post('/login', [
|
||||
'username' => $this->user->username,
|
||||
'password' => 'password',
|
||||
|
|
Loading…
Reference in New Issue