[Catalyst] Testing controller which require login.
Matt S Trout
dbix-class at trout.me.uk
Wed May 13 15:57:35 GMT 2009
On Tue, May 12, 2009 at 10:07:49PM -0700, Louis Erickson wrote:
>
> I've been neglecting my test scripts, and I'm finally getting to that
> before my app gets any bigger. I want to make sure I don't break anything
> that's working, and that it works as well as I think it does.
>
> I'm probably going to have several questions in the next few days about
> tests. I think I've got a lot of the basics working; tests pass, I have a
> sensible test database and environment. I can see fixtures from here, I
> think.
>
> I haven't been able to get a test user logging in and out yet, though.
>
> I have several sections of my application that redirect the user away if
> they are not logged in. I have another that returns a 404 if they don't
> have access, so prying users can't find it (as easily).
>
> My tests are currently based on the stubs generated by myapp_create,
> and use Catalyst::Test. I could move them to WWW::Mechanize::Catalyst if
> it would help.
>
> I can't tell if Catalyst::Test supports cookies. Does it? Or do I need
> to use WWW::Mechanize::Catalyst for that?
>
> I've read some suggestions on how to go about this, and found a couple.
>
> 1> Use WWW::Mechanize::Catalyst to log the user in
> 2> Use the mock user in config to set a user who is logged in.
>
> The problem with really logging the user in is that the login is a set of
> site-wide cookies generated by a Single Sign On system. That system may
> or may not have a test instance running. If it does, cookies stored from
> it probably won't work with cookies from 'localhost' like the local test
> app wants.
I think what you want is Test::WWW::Mechanize::Catalyst and to mock the
single sign on stuff.
After all, you're not trying to test -it-, you're trying to test your
application, right?
--
Matt S Trout Catalyst and DBIx::Class consultancy with a clue
Technical Director and a commit bit: http://shadowcat.co.uk/catalyst/
Shadowcat Systems Limited
mst (@) shadowcat.co.uk http://shadowcat.co.uk/blog/matt-s-trout/
More information about the Catalyst
mailing list