Test new validation logic
This commit is contained in:
parent
b732f70c59
commit
e32e8d1390
|
|
@ -3,6 +3,7 @@
|
|||
use System\Models\File as FileModel;
|
||||
use Database\Tester\Models\User;
|
||||
use Database\Tester\Models\SoftDeleteUser;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class AttachOneModelTest extends PluginTestCase
|
||||
{
|
||||
|
|
@ -19,13 +20,43 @@ class AttachOneModelTest extends PluginTestCase
|
|||
{
|
||||
Model::unguard();
|
||||
$user = User::create(['name' => 'Stevie', 'email' => 'stevie@email.tld']);
|
||||
$user2 = User::create(['name' => 'Joe', 'email' => 'joe@email.tld']);
|
||||
Model::reguard();
|
||||
|
||||
// Set by string
|
||||
$user->avatar = base_path().'/tests/fixtures/plugins/database/tester/assets/images/avatar.png';
|
||||
|
||||
// @todo $user->avatar currently sits as a string, not good for validation
|
||||
// this should really assert as an UploadedFile instead.
|
||||
|
||||
// Commit the file and it should snap to a File model
|
||||
$user->save();
|
||||
|
||||
$this->assertNotNull($user->avatar);
|
||||
$this->assertEquals('avatar.png', $user->avatar->file_name);
|
||||
|
||||
// Set by Uploaded file
|
||||
$sample = $user->avatar;
|
||||
$upload = new UploadedFile(
|
||||
base_path().'/tests/fixtures/plugins/database/tester/assets/images/avatar.png',
|
||||
$sample->file_name,
|
||||
$sample->content_type,
|
||||
$sample->file_size,
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$user2->avatar = $upload;
|
||||
|
||||
// The file is prepped but not yet commited, this is for validation
|
||||
$this->assertNotNull($user2->avatar);
|
||||
$this->assertEquals($upload, $user2->avatar);
|
||||
|
||||
// Commit the file and it should snap to a File model
|
||||
$user2->save();
|
||||
|
||||
$this->assertNotNull($user2->avatar);
|
||||
$this->assertEquals('avatar.png', $user2->avatar->file_name);
|
||||
}
|
||||
|
||||
public function testDeleteFlagDestroyRelationship()
|
||||
|
|
|
|||
Loading…
Reference in New Issue