test object $t->tx->req->headers->referrer question

33 visualizzazioni
Passa al primo messaggio da leggere

yanni1...@g.ucla.edu

da leggere,
7 gen 2018, 01:38:4607/01/18
a Mojolicious
Hello all,

I'm using Test::Mojo to test a course website.
Suppose I'm on the page https://somecourse.test/instructor/filecenter, which displays files and includes buttons to set due for a file (linked to /instructor/filesetdue)
InstructorFilesetdue.pm looks like this:

get '/instructor/filesetdue' => sub {

  my $c = shift;

  ...   # change the due

  $c->redirect_to($c->req->headers->referrer);   # this should redirect me back to the /instructor/filecenter

};

So in real operation, after I click the button and change the due, I should come back to /instructor/filecenter.
But for the test object $t, when I write:
       ->content_like(qr/file center, not filesetdue or login/)
I can change the due but $t ends up at the login page of my course website (As I found out, when executing $c->redirect_to($c->req->headers->referrer), $c->req->headers->referrer is actually uninitialized, so redirect_to() will direct me to "/", which then prompts to /login page).

My question is, how can I tell the test object it comes from /instructor/filecenter and that should be the referrer?

Thanks!

Ni

Dmitry L.

da leggere,
7 gen 2018, 08:22:3207/01/18
a mojol...@googlegroups.com
http://mojolicious.org/perldoc/Test/Mojo#get_ok
> Perform a GET request and check for transport errors,
> takes the same arguments as "get" in Mojo::UserAgent, except for the callback.

So, this should work

->get_ok( "https://somecourse.test/instructor/filesetdue" => { Referer
=> "/instructor/filecenter" } )
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious...@googlegroups.com.
> To post to this group, send email to mojol...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.



--
//wbr, Dmitry L.
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi