- 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-05-04 19:22:58 +00:00
/**
* A class for common methods for testing profile fields.
*/
2008-05-02 15:24:47 +00:00
class ProfileTestCase extends DrupalWebTestCase {
protected $admin_user;
protected $normal_user;
- 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-05-02 15:24:47 +00:00
function setUp() {
2008-06-05 21:55:45 +00:00
parent::setUp('profile');
2008-05-02 15:24:47 +00:00
variable_set('user_register', 1);
- 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-05-02 15:24:47 +00:00
$this->admin_user = $this->drupalCreateUser(array('administer users', 'access user profiles'));
- 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-05-02 15:24:47 +00:00
// This is the user whose profile will be edited.
$this->normal_user = $this->drupalCreateUser();
- 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-05-02 15:24:47 +00:00
/**
* Create a profile field.
*
* @param $type
* The field type to be created.
* @param $category
* The category in which the field should be created.
* @param $edit
* Additional parameters to be submitted.
* @return
* The fid of the field that was just created.
*/
function createProfileField($type = 'textfield', $category = 'simpletest', $edit = array()) {
2009-04-29 12:08:28 +00:00
$edit['title'] = $title = $this->randomName(8);
2008-05-02 15:24:47 +00:00
$edit['name'] = $form_name = 'profile_' . $title;
$edit['category'] = $category;
$edit['explanation'] = $this->randomName(50);
- 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
2009-08-21 14:27:47 +00:00
$this->drupalPost('admin/config/people/profile/add/' . $type, $edit, t('Save field'));
2009-07-28 19:18:08 +00:00
$fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField();
2008-05-02 15:24:47 +00:00
$this->assertTrue($fid, t('New Profile field has been entered in the database'));
- 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-05-02 15:24:47 +00:00
// Check that the new field is appearing on the user edit form.
2008-05-30 07:30:53 +00:00
$this->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category);
- 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-05-02 15:24:47 +00:00
// Checking field.
if ($type == 'date') {
$this->assertField($form_name . '[month]', t('Found month selection field'));
$this->assertField($form_name . '[day]', t('Found day selection field'));
$this->assertField($form_name . '[year]', t('Found day selection field'));
- 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-05-02 15:24:47 +00:00
else {
$this->assertField($form_name , t('Found form named @name', array('@name' => $form_name)));
- 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-05-02 15:24:47 +00:00
// Checking name.
$this->assertText($title, t('Checking title for field %title', array('%title' => $title)));
// Checking explanation.
$this->assertText($edit['explanation'], t('Checking explanation for field %title', array('%title' => $title)));
- 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-05-02 15:24:47 +00:00
return array(
'fid' => $fid,
'type' => $type,
'form_name' => $form_name,
'title' => $title,
'category' => $category,
);
- 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
}
2009-11-20 04:15:15 +00:00
/**
* Update a profile field.
*
* @param $fid
* The fid of the field to be updated.
* @param $type
* The type of field to be updated.
* @param $edit
* Field parameters to be submitted.
* @return
* Array representation of the updated field.
*/
function updateProfileField($fid, $type = 'textfield', $edit = array()) {
$form_name = $edit['name'];
$title = $edit['title'];
$category = $edit['category'];
$this->drupalPost('admin/config/people/profile/edit/' . $fid, $edit, t('Save field'));
// Check that the updated field is appearing on the user edit form.
$this->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category);
// Checking field.
if ($type == 'date') {
$this->assertField($form_name . '[month]', t('Found month selection field'));
$this->assertField($form_name . '[day]', t('Found day selection field'));
$this->assertField($form_name . '[year]', t('Found day selection field'));
}
else {
$this->assertField($form_name , t('Found form named @name', array('@name' => $form_name)));
}
// Checking name.
$this->assertText($title, t('Checking title for field %title', array('%title' => $title)));
// Checking explanation.
$this->assertText($edit['explanation'], t('Checking explanation for field %title', array('%title' => $title)));
return array(
'fid' => $fid,
'type' => $type,
'form_name' => $form_name,
'title' => $title,
'category' => $category,
);
}
2008-05-02 15:24:47 +00:00
/**
* Set the profile field to a random value
*
* @param $field
* The field that should be set.
* @param $value
* The value for the field, defaults to a random string.
* @return
* The value that has been assigned to
*/
function setProfileField($field, $value = NULL) {
- 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-05-02 15:24:47 +00:00
if (!isset($value)) {
$value = $this->randomName();
- 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-05-02 15:24:47 +00:00
$edit = array(
$field['form_name'] => $value,
);
$this->drupalPost('user/' . $this->normal_user->uid . '/edit/' . $field['category'], $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-05-02 15:24:47 +00:00
// Check profile page.
$content = $this->drupalGet('user/' . $this->normal_user->uid);
$this->assertText($field['title'], t('Found profile field with title %title', array('%title' => $field['title'])));
- 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-05-02 15:24:47 +00:00
if ($field['type'] != 'checkbox') {
// $value must be cast to a string in order to be found by assertText.
$this->assertText("$value", t('Found profile field with value %value', array('%value' => $value)));
- 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-05-02 15:24:47 +00:00
return $value;
- 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-05-02 15:24:47 +00:00
/**
* Delete a profile field.
*
* @param $field
* The field to be deleted.
*/
function deleteProfileField($field) {
2009-08-21 14:27:47 +00:00
$this->drupalPost('admin/config/people/profile/delete/' . $field['fid'], array(), t('Delete'));
$this->drupalGet('admin/config/people/profile');
2008-05-02 15:24:47 +00:00
$this->assertNoText($field['title'], t('Checking deleted field %title', array('%title' => $field['title'])));
- 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-05-04 19:22:58 +00:00
class ProfileTestFields extends ProfileTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-05-04 19:22:58 +00:00
return array(
'name' => 'Test single fields',
2009-07-13 21:51:42 +00:00
'description' => 'Testing profile module with add/edit/delete textfield, textarea, list, checkbox, and url fields into profile page',
'group' => 'Profile'
);
2008-05-04 19:22:58 +00:00
}
/**
* Test each of the field types. List selection and date fields are tested
* separately because they need some special handling.
*/
function testProfileFields() {
$this->drupalLogin($this->admin_user);
// Set test values for every field type.
$field_types = array(
'textfield' => $this->randomName(),
'textarea' => $this->randomName(),
'list' => $this->randomName(),
'checkbox' => 1,
2009-01-08 19:09:49 +00:00
// An underscore is an invalid character in a domain name. The method randomName can
// return an underscore.
2009-05-24 17:39:35 +00:00
'url' => 'http://www.' . str_replace('_', '', $this->randomName(10)) . '.org',
2008-05-04 19:22:58 +00:00
);
2009-11-20 04:15:15 +00:00
// For each field type, create a field, give it a value, update the field,
// and delete the field.
2008-05-04 19:22:58 +00:00
foreach ($field_types as $type => $value) {
$field = $this->createProfileField($type);
$this->setProfileField($field, $value);
2009-11-20 04:15:15 +00:00
$edit = array(
'name' => $field['form_name'],
'title' => $this->randomName(),
'category' => $field['category'],
'explanation' => $this->randomName(),
);
$field = $this->updateProfileField($field['fid'], $field['type'], $edit);
2008-05-04 19:22:58 +00:00
$this->deleteProfileField($field);
}
}
}
class ProfileTestSelect extends ProfileTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-05-04 19:22:58 +00:00
return array(
'name' => 'Test select field',
2009-07-13 21:51:42 +00:00
'description' => 'Testing profile module with add/edit/delete a select field',
'group' => 'Profile'
);
2008-05-04 19:22:58 +00:00
}
/**
2009-11-20 04:15:15 +00:00
* Create a list selection field, give it a value, update and delete the field.
2008-05-04 19:22:58 +00:00
*/
function testProfileSelectionField() {
$this->drupalLogin($this->admin_user);
$edit = array(
'options' => implode("\n", range(1, 10)),
);
$field = $this->createProfileField('selection', 'simpletest', $edit);
$this->setProfileField($field, rand(1, 10));
2009-11-20 04:15:15 +00:00
$edit = array(
'name' => $field['form_name'],
'title' => $this->randomName(),
'category' => $field['category'],
'explanation' => $this->randomName(),
);
$field = $this->updateProfileField($field['fid'], $field['type'], $edit);
2008-05-04 19:22:58 +00:00
$this->deleteProfileField($field);
}
}
class ProfileTestDate extends ProfileTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-05-04 19:22:58 +00:00
return array(
'name' => 'Test date field',
2009-07-13 21:51:42 +00:00
'description' => 'Testing profile module with add/edit/delete a date field',
'group' => 'Profile'
);
2008-05-04 19:22:58 +00:00
}
/**
2009-11-20 04:15:15 +00:00
* Create a date field, give it a value, update and delete the field.
2008-05-04 19:22:58 +00:00
*/
function testProfileDateField() {
$this->drupalLogin($this->admin_user);
variable_set('date_format_short', 'm/d/Y - H:i');
$field = $this->createProfileField('date');
// Set date to January 09, 1983
$edit = array(
2008-05-30 07:30:53 +00:00
$field['form_name'] . '[month]' => 1,
$field['form_name'] . '[day]' => 9,
$field['form_name'] . '[year]' => 1983,
2008-05-04 19:22:58 +00:00
);
$this->drupalPost('user/' . $this->normal_user->uid . '/edit/' . $field['category'], $edit, t('Save'));
// Check profile page.
$this->drupalGet('user/' . $this->normal_user->uid);
$this->assertText($field['title'], t('Found profile field with title %title', array('%title' => $field['title'])));
$this->assertText('01/09/1983', t('Found date profile field.'));
2009-11-20 04:15:15 +00:00
$edit = array(
'name' => $field['form_name'],
'title' => $this->randomName(),
'category' => $field['category'],
'explanation' => $this->randomName(),
);
$field = $this->updateProfileField($field['fid'], $field['type'], $edit);
2008-05-04 19:22:58 +00:00
$this->deleteProfileField($field);
}
}
class ProfileTestWeights extends ProfileTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-05-04 19:22:58 +00:00
return array(
'name' => 'Test field weights',
2009-07-13 21:51:42 +00:00
'description' => 'Testing profile modules weigting of fields',
'group' => 'Profile'
);
2008-05-04 19:22:58 +00:00
}
function testProfileFieldWeights() {
$this->drupalLogin($this->admin_user);
$category = $this->randomName();
$field1 = $this->createProfileField('textfield', $category, array('weight' => 1));
$field2 = $this->createProfileField('textfield', $category, array('weight' => -1));
2009-04-29 12:08:28 +00:00
$this->setProfileField($field1, $this->randomName(8));
$this->setProfileField($field2, $this->randomName(8));
2008-05-04 19:22:58 +00:00
$profile_edit = $this->drupalGet('user/' . $this->normal_user->uid . '/edit/' . $category);
$this->assertTrue(strpos($profile_edit, $field1['title']) > strpos($profile_edit, $field2['title']), t('Profile field weights are respected on the user edit form.'));
$profile_page = $this->drupalGet('user/' . $this->normal_user->uid);
$this->assertTrue(strpos($profile_page, $field1['title']) > strpos($profile_page, $field2['title']), t('Profile field weights are respected on the user profile page.'));
}
}
2008-10-10 07:49:49 +00:00
/**
* Test profile field autocompletion and access.
*/
class ProfileTestAutocomplete extends ProfileTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-10-10 07:49:49 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Autocompletion',
'description' => 'Test profile fields with autocompletion.',
'group' => 'Profile'
2008-10-10 07:49:49 +00:00
);
}
/**
* Tests profile field autocompletion and access.
*/
function testAutocomplete() {
$this->drupalLogin($this->admin_user);
// Create a new profile field with autocompletion enabled.
$category = $this->randomName();
$field = $this->createProfileField('textfield', $category, array('weight' => 1, 'autocomplete' => 1));
// Enter profile field value.
$field['value'] = $this->randomName();
$this->setProfileField($field, $field['value']);
// Set some html for what we want to see in the page output later.
2009-10-05 01:18:26 +00:00
$autocomplete_html = '<input class="autocomplete" type="hidden" id="' . drupal_html_id('edit-' . $field['form_name'] . '-autocomplete') . '" value="' . url('profile/autocomplete/' . $field['fid'], array('absolute' => TRUE)) . '" disabled="disabled" />';
$field_html = '<input type="text" maxlength="255" name="' . $field['form_name'] . '" id="' . drupal_html_id('edit-' . $field['form_name']) . '" size="60" value="' . $field['value'] . '" class="form-text form-autocomplete required" />';
2008-10-10 07:49:49 +00:00
// Check that autocompletion html is found on the user's profile edit page.
$this->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category);
$this->assertRaw($autocomplete_html, t('Autocomplete found.'));
$this->assertRaw('misc/autocomplete.js', t('Autocomplete JavaScript found.'));
$this->assertRaw('class="form-text form-autocomplete"', t('Autocomplete form element class found.'));
// Check the autocompletion path using the first letter of our user's profile
// field value to make sure access is allowed and a valid result if found.
$this->drupalGet('profile/autocomplete/' . $field['fid'] . '/' . $field['value'][0]);
$this->assertResponse(200, t('Autocomplete path allowed to user with permission.'));
$this->assertRaw($field['value'], t('Autocomplete value found.'));
// Logout and login with a user without the 'access user profiles' permission.
$this->drupalLogout();
$this->drupalLogin($this->normal_user);
// Check that autocompletion html is not found on the user's profile edit page.
$this->drupalGet('user/' . $this->normal_user->uid . '/edit/' . $category);
$this->assertNoRaw($autocomplete_html, t('Autocomplete not found.'));
// User should be denied access to the profile autocomplete path.
$this->drupalGet('profile/autocomplete/' . $field['fid'] . '/' . $field['value'][0]);
$this->assertResponse(403, t('Autocomplete path denied to user without permission.'));
}
}
2008-12-16 23:57:33 +00:00
class ProfileBlockTestCase extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-12-16 23:57:33 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Block availability',
'description' => 'Check if the author-information block is available.',
'group' => 'Profile',
2008-12-16 23:57:33 +00:00
);
}
function setUp() {
parent::setUp('profile');
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer blocks'));
$this->drupalLogin($admin_user);
}
function testAuthorInformationBlock() {
// Set block title to confirm that the interface is availble.
2009-10-16 23:48:38 +00:00
$this->drupalPost('admin/structure/block/manage/profile/author-information/configure', array('title' => $this->randomName(8)), t('Save block'));
2008-12-16 23:57:33 +00:00
$this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
// Set the block to a region to confirm block is availble.
$edit = array();
$edit['profile_author-information[region]'] = 'footer';
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
2008-12-16 23:57:33 +00:00
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
}
}
2010-03-08 15:46:58 +00:00
/**
* Test profile browsing.
*/
class ProfileTestBrowsing extends ProfileTestCase {
public static function getInfo() {
return array(
'name' => 'Profile browsing',
'description' => 'Test profile browsing.',
'group' => 'Profile',
);
}
/**
* Test profile browsing.
*/
function testProfileBrowsing() {
$this->drupalLogin($this->admin_user);
$field = $this->createProfileField('list', 'simpletest', array('page' => '%value'));
// Set a random value for the profile field.
$value = $this->setProfileField($field);
// Check that user is found on the profile browse page.
$this->drupalGet("profile/{$field['form_name']}/$value");
$this->assertText($this->normal_user->name);
}
}
2008-05-04 19:22:58 +00:00
/**
* TODO:
* - Test field visibility
* - Test required fields
* - Test fields on registration form
* - Test updating fields
*/