Ado

 view release on metacpan or  search on metacpan

t/command/adoplugin-01.t  view on Meta::CPAN

isa_ok(
    $c->run(
        -n => $name,
        -c => 1,
        -t => 'testatii'
    ),
    $command
);
my $crud_class = 'Ado::Command::generate::crud';
ok(ref($c->crud) eq $crud_class,     '$c->crud ISA ' . $crud_class);
ok(ref($c->crud->routes) eq 'ARRAY', '$c->crud->routes ISA ARRAY');

# test generated plugin
# make new lib directory findable by Ado
unshift @INC, catdir($tempdir, "Ado-Plugin-$name", 'lib');

use_ok($class);
isa_ok(my $plugin = $class->new->register($t->app, {'аз' => 'ти'}), 'Ado::Plugin', $name);

ok($plugin->home_dir =~ /Ado-Plugin-$name$/, '$plugin->home_dir ends with ' . "Ado-Plugin-$name");
is( $plugin->config_dir,
    catdir($tempdir, "Ado-Plugin-$name", 'etc', 'plugins'),
    'right config directory'
);

# Remove generic routes (for this test only) so newly generated routes can match.
# In a normal application startup generic routes will always match last.
# It is expected all plugins to load their routes by the time the generic routes load.
# This means it is ok to keep them in ado.conf
#http://localhost:3000/perldoc/Mojolicious/Guides/Routing#Rearranging-routes
$ado->routes->find('controller')->remove();
$ado->routes->find('controlleraction')->remove();
$ado->routes->find('controlleractionid')->remove();

# $ado->start("routes");
# Test generated routes
$t->get_ok('/testatii.json')->status_is(200);
$t->get_ok('/testatii/list?format=html')->status_is(200)
  ->content_like(qr|table.+id</th>.+permissions</th.+Hello</td.+Hello2|smx);

# needs login
$t->post_ok(
    '/testatii/create.html' => form => {
        title => 'Hello3',
        body =>
          'Ала, бала, ница турска паница, Хей гиди Ванчо, наш капитанчо...'
    }
  )->status_is(302)    #requires authentication
  ->header_is('Location' => '/login', 'redirected to /login');
my $login_url = $t->tx->res->headers->header('Location');

# Login after following the Location header (redirect)
$t->get_ok($login_url);

#get the csrf fields
my $form       = $t->tx->res->dom->at('#login_form');
my $csrf_token = $form->at('[name="csrf_token"]')->{value};
my $form_hash  = {
    _method        => 'login/ado',
    login_name     => 'test1',
    login_password => '',
    csrf_token     => $csrf_token,
    digest         => Mojo::Util::sha1_hex($csrf_token . Mojo::Util::sha1_hex('test1test1')),
};
$t->post_ok($login_url => {} => form => $form_hash)->status_is(302)
  ->header_is('Location' => '/testatii/create.html', 'redirected back to /testatii/create');
my $create_url = $t->tx->res->headers->header('Location');

#now we can create a new resouce after authenticating
$t->post_ok(
    $create_url => {Accept => 'text/html'} => form => {
        title => 'Hello3',
        body =>
          'Ала, бала, ница турска паница, Хей гиди Ванчо, наш капитанчо...'
    }
);
$t->get_ok('/testatii/read/3.html')->status_is(200)
  ->content_like(qr|Hello3|smx, 'reading created content - ok');

=pod
=cut

chdir $dir;
done_testing();




( run in 0.626 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )