I have a function that returns a file for the user avatar and I want to create tests for it. What I want to do is to check the name of the file.
This is the function:
sub get_avatar {
my $self = shift;
my $username = $self->stash('username');
my $home = Mojo::Home->new;
$home->detect('Project');
my $path = $home->child('users', 'avatars', "$username");
$path = $home->child('img', 'default.png') if !(-e $path);
$self->render_file('filepath' => $path);
}
And this is the test:
$file = $t->get_ok('/user/username/avatar')->status_is(200);
//use Data::Dumper;
//diag Dumper($file);
ok $file =~ 'username';
I want to check if the name of the $file is equivalent to 'username'(which is the name of the file from the server) or 'default' if it is a default avatar.
Aucun commentaire:
Enregistrer un commentaire