sending a cookie in the simpletest browser

Events happening in the community are now at Drupal community events on www.drupal.org.
greggles's picture

I need to test cookie integration with a 3rd party site.

The 3rd party site sets a cookie, Drupal sees this cookie, validates it, and logs in the user. I planned to test this by setting a cookie in my simpletest

I tried a couple of variations on:

<?php
$this
->drupalGet('node', NULL, array('Cookie: cookiename=cookievalue;'));
?>

but the "cookiename=cookievalue" bits always got jammed onto the end of the SESS... cookie.

I grepped through core and didn't find any situations where we are sending a cookie along with the drupalGet. Any advice?

Comments

Couldn't browse to a menu

moshe weitzman's picture

Couldn't you browse to a menu callback thats sets the cookie and then to /node (in your example).

could do

greggles's picture

I certainly could do that, I thought of a few other potential solutions to the problem based around adding test specific code to my regular application but rejected them on principle. Do we have other situations where code for testing exists outside of the .test files? Is there a style guideline for that?

--
Growing Venture Solutions | Drupal Dashboard | Learn more about Drupal - buy a Drupal Book

We have lots of testing

moshe weitzman's picture

We have lots of testing modules under simpletest/tests. These are hidden from the admin/build/modules page with a .info param. Does that qualify as "ode for testing exists outside of the .test files".

This may not be possible

grendzy's picture

This may not be possible with the current simpletest infrastructure. Even cURL itself seems to lack the ability to set or otherwise interact with cookies. I've started http://drupal.org/node/457804, please let us know if you discover anything.

Use mock_web?

b508's picture

I think I could easily add cookie settings to mock_web. See recent posting here. Would this work for you?

seems decent

greggles's picture

The mock_web idea seems solid. I definitely think it would be worth adding to the core simpletest features.

--
Growing Venture Solutions | Drupal Dashboard | Learn more about Drupal - buy a Drupal Book

cookie

Testing and Quality Assurance

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: