- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
<?php
// $Id$
2008-06-24 21:51:03 +00:00
/**
* Test the sitewide contact form.
*/
class ContactSitewideTestCase extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Site-wide contact form',
'description' => 'Tests site-wide contact form functionality.',
'group' => 'Contact',
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
);
}
function setUp() {
parent::setUp('contact');
}
/**
* Test configuration options and site-wide contact form.
*/
function testSiteWideContact() {
2008-12-30 16:43:20 +00:00
// Create and login administrative user.
2009-10-09 00:54:33 +00:00
$admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalLogin($admin_user);
2009-10-09 00:54:33 +00:00
2009-09-26 00:13:19 +00:00
$flood_limit = 3;
variable_set('contact_threshold_limit', $flood_limit);
variable_set('contact_threshold_window', 600);
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Set settings.
$edit = array();
$edit['contact_default_status'] = TRUE;
2009-09-26 00:13:19 +00:00
$this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.'));
// Delete old categories to ensure that new categories are used.
$this->deleteCategories();
2008-09-17 06:54:11 +00:00
// Ensure that the contact form won't be shown without categories.
2009-10-08 08:16:54 +00:00
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
2008-09-17 06:54:11 +00:00
$this->drupalLogout();
$this->drupalGet('contact');
2009-04-21 09:27:52 +00:00
$this->assertResponse(404);
2008-09-17 06:54:11 +00:00
$this->drupalLogin($admin_user);
2009-04-21 09:27:52 +00:00
$this->drupalGet('contact');
$this->assertResponse(200);
$this->assertText(t('The contact form has not been configured.'));
2008-09-17 06:54:11 +00:00
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Add categories.
// Test invalid recipients.
2009-04-05 12:10:56 +00:00
$invalid_recipients = array('invalid', 'invalid@', 'invalid@site.', '@site.', '@site.com');
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
foreach ($invalid_recipients as $invalid_recipient) {
$this->addCategory($this->randomName(16), $invalid_recipient, '', FALSE);
2008-05-30 07:30:53 +00:00
$this->assertRaw(t('%recipient is an invalid e-mail address.', array('%recipient' => $invalid_recipient)), t('Caught invalid recipient (' . $invalid_recipient . ').'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2008-07-02 20:05:11 +00:00
// Test validation of empty category and recipients fields.
$this->addCategory($category = '', '', '', TRUE);
$this->assertText(t('Category field is required.'), t('Caught empty category field'));
$this->assertText(t('Recipients field is required.'), t('Caught empty recipients field.'));
2008-09-17 06:54:11 +00:00
// Create first valid category.
2008-07-22 20:08:44 +00:00
$recipients = array('simpletest@example.com', 'simpletest2@example.com', 'simpletest3@example.com');
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE);
2009-10-09 02:34:07 +00:00
$this->assertRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category successfully saved.'));
2008-09-15 20:48:10 +00:00
2009-04-21 05:05:27 +00:00
// Make sure the newly created category is included in the list of categories.
$this->assertNoUniqueText($category, t('New category included in categories list.'));
2008-09-17 06:54:11 +00:00
// Test update contact form category.
2008-08-02 05:16:47 +00:00
$categories = $this->getCategories();
$category_id = $this->updateCategory($categories, $category = $this->randomName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE);
2009-03-08 05:08:22 +00:00
$category_array = db_query("SELECT category, recipients, reply, selected FROM {contact} WHERE cid = :cid", array(':cid' => $category_id))->fetchAssoc();
2008-08-02 05:16:47 +00:00
$this->assertEqual($category_array['category'], $category);
$this->assertEqual($category_array['recipients'], $recipients_str);
$this->assertEqual($category_array['reply'], $reply);
$this->assertFalse($category_array['selected']);
2009-10-09 02:34:07 +00:00
$this->assertRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category successfully saved.'));
2008-09-15 20:48:10 +00:00
2008-09-17 06:54:11 +00:00
// Ensure that the contact form is shown without a category selection input.
2009-10-08 08:16:54 +00:00
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
2008-09-17 06:54:11 +00:00
$this->drupalLogout();
$this->drupalGet('contact');
2009-04-30 21:44:20 +00:00
$this->assertText(t('Your e-mail address'), t('Contact form is shown when there is one category.'));
2008-09-17 06:54:11 +00:00
$this->assertNoText(t('Category'), t('When there is only one category, the category selection element is hidden.'));
$this->drupalLogin($admin_user);
// Add more categories.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1])), '', FALSE);
2009-10-09 02:34:07 +00:00
$this->assertRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category successfully saved.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE);
2009-10-09 02:34:07 +00:00
$this->assertRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category successfully saved.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2008-04-25 18:26:02 +00:00
// Clear flood table in preparation for flood test and allow other checks to complete.
2009-03-08 05:08:22 +00:00
db_delete('flood')->execute();
$num_records_after = db_query("SELECT COUNT(*) FROM {flood}")->fetchField();
$this->assertIdentical($num_records_after, '0', t('Flood table emptied.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalLogout();
2009-10-08 08:16:54 +00:00
// Check to see that anonymous user cannot see contact page without permission.
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalGet('contact');
$this->assertResponse(403, t('Access denied to anonymous user without permission.'));
// Give anonymous user permission and see that page is viewable.
2009-10-08 08:16:54 +00:00
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalGet('contact');
$this->assertResponse(200, t('Access granted to anonymous user with permission.'));
// Submit contact form with invalid values.
$this->submitContact('', $recipients[0], $this->randomName(16), $categories[0], $this->randomName(64));
$this->assertText(t('Your name field is required.'), t('Name required.'));
$this->submitContact($this->randomName(16), '', $this->randomName(16), $categories[0], $this->randomName(64));
$this->assertText(t('Your e-mail address field is required.'), t('E-mail required.'));
$this->submitContact($this->randomName(16), $invalid_recipients[0], $this->randomName(16), $categories[0], $this->randomName(64));
$this->assertText(t('You must enter a valid e-mail address.'), t('Valid e-mail required.'));
$this->submitContact($this->randomName(16), $recipients[0], '', $categories[0], $this->randomName(64));
$this->assertText(t('Subject field is required.'), t('Subject required.'));
$this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $categories[0], '');
$this->assertText(t('Message field is required.'), t('Message required.'));
2008-09-17 06:54:11 +00:00
// Test contact form with no default category selected.
2009-03-08 05:08:22 +00:00
db_update('contact')
->fields(array('selected' => 0))
->execute();
2008-09-17 06:54:11 +00:00
$this->drupalGet('contact');
$this->assertRaw(t('- Please choose -'), t('Without selected categories the visitor is asked to chose a category.'));
// Submit contact form with invalid category id (cid 0).
$this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), 0, '');
$this->assertText(t('You must select a valid category.'), t('Valid category required.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Submit contact form with correct values and check flood interval.
2009-09-26 00:13:19 +00:00
for ($i = 0; $i < $flood_limit; $i++) {
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $categories[0], $this->randomName(64));
$this->assertText(t('Your message has been sent.'), t('Message sent.'));
}
// Submit contact form one over limit.
$this->drupalGet('contact');
2009-12-07 06:07:19 +00:00
$this->assertResponse(403, t('Access denied to anonymous user after reaching message treshold.'));
2009-09-26 00:13:19 +00:00
$this->assertRaw(t('You cannot send more than %number messages in @interval. Please try again later.', array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(600))), t('Message threshold reached.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Delete created categories.
$this->drupalLogin($admin_user);
$this->deleteCategories();
}
2009-05-27 15:14:27 +00:00
/**
* Test auto-reply on the site-wide contact form.
*/
function testAutoReply() {
// Create and login administrative user.
2009-10-09 00:54:33 +00:00
$admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer permissions', 'administer users'));
2009-05-27 15:14:27 +00:00
$this->drupalLogin($admin_user);
// Set up three categories, 2 with an auto-reply and one without.
$foo_autoreply = $this->randomString(40);
$bar_autoreply = $this->randomString(40);
$this->addCategory('foo', 'foo@example.com', $foo_autoreply, FALSE);
$this->addCategory('bar', 'bar@example.com', $bar_autoreply, FALSE);
$this->addCategory('no_autoreply', 'bar@example.com', '', FALSE);
// Test the auto-reply for category 'foo'.
$email = $this->randomName(32) . '@example.com';
$subject = $this->randomString(64);
2009-10-09 02:54:10 +00:00
$this->submitContact($this->randomName(16), $email, $subject, 2, $this->randomString(128));
2009-05-27 15:14:27 +00:00
// We are testing the auto-reply, so there should be one e-mail going to the sender.
$captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'foo@example.com'));
$this->assertEqual(count($captured_emails), 1, t('Auto-reply e-mail was sent to the sender for category "foo".'), t('Contact'));
2009-10-16 03:01:55 +00:00
$this->assertEqual($captured_emails[0]['body'], drupal_html_to_text($foo_autoreply), t('Auto-reply e-mail body is correct for category "foo".'), t('Contact'));
2009-05-27 15:14:27 +00:00
// Test the auto-reply for category 'bar'.
$email = $this->randomName(32) . '@example.com';
2009-10-09 02:54:10 +00:00
$this->submitContact($this->randomName(16), $email, $this->randomString(64), 3, $this->randomString(128));
2009-05-27 15:14:27 +00:00
// Auto-reply for category 'bar' should result in one auto-reply e-mail to the sender.
$captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'bar@example.com'));
$this->assertEqual(count($captured_emails), 1, t('Auto-reply e-mail was sent to the sender for category "bar".'), t('Contact'));
2009-10-16 03:01:55 +00:00
$this->assertEqual($captured_emails[0]['body'], drupal_html_to_text($bar_autoreply), t('Auto-reply e-mail body is correct for category "bar".'), t('Contact'));
2009-05-27 15:14:27 +00:00
// Verify that no auto-reply is sent when the auto-reply field is left blank.
$email = $this->randomName(32) . '@example.com';
2009-10-09 02:54:10 +00:00
$this->submitContact($this->randomName(16), $email, $this->randomString(64), 4, $this->randomString(128));
2009-05-27 15:14:27 +00:00
$captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'no_autoreply@example.com'));
$this->assertEqual(count($captured_emails), 0, t('No auto-reply e-mail was sent to the sender for category "no-autoreply".'), t('Contact'));
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
* Add a category.
*
* @param string $category Name of category.
* @param string $recipients List of recipient e-mail addresses.
* @param string $reply Auto-reply text.
* @param boolean $selected Defautly selected.
*/
function addCategory($category, $recipients, $reply, $selected) {
$edit = array();
$edit['category'] = $category;
$edit['recipients'] = $recipients;
$edit['reply'] = $reply;
$edit['selected'] = ($selected ? '1' : '0');
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/contact/add', $edit, t('Save'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2008-08-02 05:16:47 +00:00
/**
* Update a category.
*
* @param string $category Name of category.
* @param string $recipients List of recipient e-mail addresses.
* @param string $reply Auto-reply text.
* @param boolean $selected Defautly selected.
*/
function updateCategory($categories, $category, $recipients, $reply, $selected) {
$category_id = $categories[array_rand($categories)];
$edit = array();
$edit['category'] = $category;
$edit['recipients'] = $recipients;
$edit['reply'] = $reply;
$edit['selected'] = ($selected ? '1' : '0');
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/contact/edit/' . $category_id, $edit, t('Save'));
2009-05-24 17:39:35 +00:00
return ($category_id);
2008-08-02 05:16:47 +00:00
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
* Submit contact form.
*
* @param string $name Name.
* @param string $mail E-mail address.
* @param string $subject Subject.
* @param integer $cid Category id.
* @param string $message Message.
*/
function submitContact($name, $mail, $subject, $cid, $message) {
$edit = array();
$edit['name'] = $name;
$edit['mail'] = $mail;
$edit['subject'] = $subject;
$edit['cid'] = $cid;
$edit['message'] = $message;
2009-05-10 05:06:50 +00:00
$this->drupalPost('contact', $edit, t('Send message'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
/**
* Delete all categories.
*/
function deleteCategories() {
$categories = $this->getCategories();
foreach ($categories as $category) {
2009-03-08 05:08:22 +00:00
$category_name = db_query("SELECT category FROM {contact} WHERE cid = :cid", array(':cid' => $category))->fetchField();
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/contact/delete/' . $category, array(), t('Delete'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->assertRaw(t('Category %category has been deleted.', array('%category' => $category_name)), t('Category deleted sucessfully.'));
}
}
/**
* Get list category ids.
*
* @return array Category ids.
*/
function getCategories() {
2009-03-08 05:08:22 +00:00
$categories = db_query('SELECT cid FROM {contact}')->fetchCol();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
return $categories;
}
}
2008-06-24 21:51:03 +00:00
/**
* Test the personal contact form.
*/
class ContactPersonalTestCase extends DrupalWebTestCase {
2009-10-10 19:54:15 +00:00
private $admin_user;
private $web_user;
private $contact_user;
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-06-24 21:51:03 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Personal contact form',
'description' => 'Tests personal contact form functionality.',
'group' => 'Contact',
2008-06-24 21:51:03 +00:00
);
}
function setUp() {
parent::setUp('contact');
2009-10-10 19:54:15 +00:00
// Create an admin user.
$this->admin_user = $this->drupalCreateUser(array('administer contact forms', 'administer users'));
// Create some normal users with their contact forms enabled by default.
variable_set('contact_default_status', TRUE);
2009-10-11 18:34:10 +00:00
$this->web_user = $this->drupalCreateUser(array('access user contact forms'));
2009-10-10 19:54:15 +00:00
$this->contact_user = $this->drupalCreateUser();
2008-06-24 21:51:03 +00:00
}
/**
2009-10-10 19:54:15 +00:00
* Test personal contact form access.
2008-06-24 21:51:03 +00:00
*/
2009-10-10 19:54:15 +00:00
function testPersonalContactAccess() {
// Test allowed access to user with contact form enabled.
$this->drupalLogin($this->web_user);
$this->drupalGet('user/' . $this->contact_user->uid . '/contact');
$this->assertResponse(200);
2009-10-09 00:54:33 +00:00
2009-10-10 19:54:15 +00:00
// Test denied access to the user's own contact form.
$this->drupalGet('user/' . $this->web_user->uid . '/contact');
$this->assertResponse(403);
2008-06-24 21:51:03 +00:00
2009-10-10 19:54:15 +00:00
// Test always denied access to the anonymous user contact form.
$this->drupalGet('user/0/contact');
$this->assertResponse(403);
2009-10-11 18:34:10 +00:00
// Test that anonymous users can access the contact form.
$this->drupalLogout();
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access user contact forms'));
$this->drupalGet('user/' . $this->contact_user->uid . '/contact');
$this->assertResponse(200);
// Revoke the personal contact permission for the anonymous user.
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access user contact forms'));
$this->drupalGet('user/' . $this->contact_user->uid . '/contact');
$this->assertResponse(403);
2009-10-10 19:54:15 +00:00
// Disable the personal contact form.
$this->drupalLogin($this->admin_user);
$edit = array('contact_default_status' => FALSE);
2009-09-26 00:13:19 +00:00
$this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
2008-06-24 21:51:03 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.'));
$this->drupalLogout();
2009-10-10 19:54:15 +00:00
// Re-create our contacted user with personal contact forms disabled by
// default.
$this->contact_user = $this->drupalCreateUser();
2008-06-24 21:51:03 +00:00
2009-10-10 19:54:15 +00:00
// Test denied access to a user with contact form disabled.
$this->drupalLogin($this->web_user);
$this->drupalGet('user/' . $this->contact_user->uid . '/contact');
$this->assertResponse(403);
2008-06-24 21:51:03 +00:00
2009-10-10 19:54:15 +00:00
// Test allowed access for admin user to a user with contact form disabled.
$this->drupalLogin($this->admin_user);
$this->drupalGet('user/' . $this->contact_user->uid . '/contact');
$this->assertResponse(200);
}
2008-06-24 21:51:03 +00:00
2009-10-10 19:54:15 +00:00
/**
* Test the personal contact form flood protection.
*/
function testPersonalContactFlood() {
$flood_limit = 3;
variable_set('contact_threshold_limit', $flood_limit);
2008-06-24 21:51:03 +00:00
2008-09-16 18:18:02 +00:00
// Clear flood table in preparation for flood test and allow other checks to complete.
2009-03-08 05:08:22 +00:00
db_delete('flood')->execute();
$num_records_flood = db_query("SELECT COUNT(*) FROM {flood}")->fetchField();
2009-10-10 19:54:15 +00:00
$this->assertIdentical($num_records_flood, '0', 'Flood table emptied.');
$this->drupalLogin($this->web_user);
2008-09-16 18:18:02 +00:00
// Submit contact form with correct values and check flood interval.
2009-09-26 00:13:19 +00:00
for ($i = 0; $i < $flood_limit; $i++) {
2009-10-10 19:54:15 +00:00
$this->submitPersonalContact($this->contact_user);
$this->assertText(t('Your message has been sent.'), 'Message sent.');
2008-09-16 18:18:02 +00:00
}
// Submit contact form one over limit.
2009-10-10 19:54:15 +00:00
$this->drupalGet('user/' . $this->contact_user->uid. '/contact');
$this->assertRaw(t('You cannot send more than %number messages in @interval. Please try again later.', array('%number' => $flood_limit, '@interval' => format_interval(variable_get('contact_threshold_window', 3600)))), 'Normal user denied access to flooded contact form.');
2008-06-24 21:51:03 +00:00
2009-10-10 19:54:15 +00:00
// Test that the admin user can still access the contact form even though
// the flood limit was reached.
$this->drupalLogin($this->admin_user);
$this->assertNoText('Please try again later.', 'Admin user not denied access to flooded contact form.');
}
2008-06-24 21:51:03 +00:00
2009-10-10 19:54:15 +00:00
/**
* Fill out a user's personal contact form and submit.
*
* @param $account
* A user object of the user being contacted.
* @param $message
* An optional array with the form fields being used.
*/
protected function submitPersonalContact($account, array $message = array()) {
$message += array(
'subject' => $this->randomName(16),
'message' => $this->randomName(64),
);
$this->drupalPost('user/' . $account->uid . '/contact', $message, t('Send message'));
2008-06-24 21:51:03 +00:00
}
2008-07-22 20:08:44 +00:00
}