Game-FaceGenerator

 view release on metacpan or  search on metacpan

t/face.t  view on Meta::CPAN

#!/usr/bin/env perl

# Copyright (C) 2015 Alex Schroeder <alex@gnu.org>

# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

use Modern::Perl;
use Test::More;
use Test::Mojo;
use FindBin;
use GD;
use strict;
use warnings;
use File::Temp qw(tempdir);
use File::Slurper qw(write_binary);

my $t = Test::Mojo->new('Game::FaceGenerator');
$t->app->config->{contrib} = 'share';

sub png_images_ok {
  my $images = shift;
  ok($images, "images provided by " . $t->tx->req->url);
  for my $image (@$images) {
    my $url = $image->attr('src');
    $t->get_ok($url)
	->status_is(200)
	->header_is('Content-Type' => 'image/png');
  }
}

$t->get_ok('/')
    ->status_is(200)
    ->text_is('h1' => 'Faces for your RPG Characters')
    # alex
    ->element_exists('li a[href="/view/alex/woman"]')
    # but not debugging alex
    ->element_exists_not('li a[href="/debug/alex"]');

# set up an account in the config file
$t->app->config('users')->{alex} = '*secret*';

# failed login to access debug mode
$t->post_ok('/login' => form =>  {
  username => 'alex',
  password => 'fnork' })
    ->status_is(200)
    ->content_like(qr/login failed/i)
    ->element_exists_not('li a[href="/debug/alex"]');

# successful login redirects to the main page
$t->post_ok('/login' => form =>  {
  username => 'alex',
  password => '*secret*' })
    ->status_is(302)
    ->header_is(Location => '/');

# debugging alex works, now
$t->get_ok('/')
    ->element_exists('li a[href="/debug/alex"]');

$t->get_ok('/view')
    ->status_is(302)
    ->header_is(Location => '/view/alex/woman');

$t->get_ok('/gallery')
    ->status_is(302)
    ->header_is(Location => '/gallery/alex/man');



( run in 2.896 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )