- 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
2011-02-04 18:42:22 +00:00
/**
2011-09-29 03:29:59 +00:00
* @file
2012-01-03 04:36:15 +00:00
* Tests for the Comment module.
2011-02-04 18:42:22 +00:00
*/
2008-09-08 21:37:21 +00:00
class CommentHelperCase extends DrupalWebTestCase {
2012-03-13 03:16:40 +00:00
protected $profile = 'standard';
- 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
protected $admin_user;
protected $web_user;
protected $node;
function setUp() {
2009-06-03 06:52:29 +00:00
parent::setUp('comment', 'search');
2009-10-08 08:16:54 +00:00
// Create users and test node.
$this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks'));
2010-01-03 22:30:26 +00:00
$this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments'));
2009-10-08 08:16:54 +00:00
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
- 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-09-08 21:37:21 +00:00
/**
2012-01-03 04:36:15 +00:00
* Posts a comment.
2008-09-08 21:37:21 +00:00
*
2012-04-26 16:44:37 +00:00
* @param Node|NULL $node
* Node to post comment on or NULL to post to the previusly loaded page.
2009-12-13 09:14:21 +00:00
* @param $comment
* Comment body.
* @param $subject
* Comment subject.
* @param $contact
* Set to NULL for no contact info, TRUE to ignore success checking, and
* array of values to set contact info.
2008-09-08 21:37:21 +00:00
*/
2009-12-13 09:14:21 +00:00
function postComment($node, $comment, $subject = '', $contact = NULL) {
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2008-09-08 21:37:21 +00:00
$edit = array();
2010-01-07 05:23:52 +00:00
$edit['comment_body[' . $langcode . '][0][value]'] = $comment;
2008-09-08 21:37:21 +00:00
2009-10-16 13:20:16 +00:00
$preview_mode = variable_get('comment_preview_article', DRUPAL_OPTIONAL);
$subject_mode = variable_get('comment_subject_field_article', 1);
2008-09-08 21:37:21 +00:00
2009-10-16 13:20:16 +00:00
// Must get the page before we test for fields.
2008-09-08 21:37:21 +00:00
if ($node !== NULL) {
$this->drupalGet('comment/reply/' . $node->nid);
}
2009-10-16 13:20:16 +00:00
if ($subject_mode == TRUE) {
$edit['subject'] = $subject;
}
else {
2010-08-05 23:53:39 +00:00
$this->assertNoFieldByName('subject', '', t('Subject field not found.'));
2009-10-16 13:20:16 +00:00
}
if ($contact !== NULL && is_array($contact)) {
$edit += $contact;
}
switch ($preview_mode) {
case DRUPAL_REQUIRED:
// Preview required so no save button should be found.
2010-08-05 23:53:39 +00:00
$this->assertNoFieldByName('op', t('Save'), t('Save button not found.'));
2009-10-16 13:20:16 +00:00
$this->drupalPost(NULL, $edit, t('Preview'));
// Don't break here so that we can test post-preview field presence and
// function below.
case DRUPAL_OPTIONAL:
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('op', t('Preview'), t('Preview button found.'));
$this->assertFieldByName('op', t('Save'), t('Save button found.'));
2009-10-16 13:20:16 +00:00
$this->drupalPost(NULL, $edit, t('Save'));
break;
case DRUPAL_DISABLED:
2010-08-05 23:53:39 +00:00
$this->assertNoFieldByName('op', t('Preview'), t('Preview button not found.'));
$this->assertFieldByName('op', t('Save'), t('Save button found.'));
2009-10-16 13:20:16 +00:00
$this->drupalPost(NULL, $edit, t('Save'));
break;
2008-09-08 21:37:21 +00:00
}
$match = array();
// Get comment ID
2009-09-22 07:36:57 +00:00
preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
2008-09-08 21:37:21 +00:00
// Get comment.
if ($contact !== TRUE) { // If true then attempting to find error message.
2009-02-07 20:10:40 +00:00
if ($subject) {
$this->assertText($subject, 'Comment subject posted.');
}
2008-09-19 03:11:53 +00:00
$this->assertText($comment, 'Comment body posted.');
2010-08-05 23:53:39 +00:00
$this->assertTrue((!empty($match) && !empty($match[1])), t('Comment id found.'));
2008-09-08 21:37:21 +00:00
}
if (isset($match[1])) {
2011-12-05 12:12:15 +00:00
return entity_create('comment', array('id' => $match[1], 'subject' => $subject, 'comment' => $comment));
2008-09-08 21:37:21 +00:00
}
}
/**
* Checks current page for specified comment.
*
2012-04-13 08:01:13 +00:00
* @param Comment $comment
2012-01-03 04:36:15 +00:00
* The comment object.
* @param boolean $reply
* Boolean indicating whether the comment is a reply to another comment.
*
* @return boolean
* Boolean indicating whether the comment was found.
2008-09-08 21:37:21 +00:00
*/
2012-04-13 08:01:13 +00:00
function commentExists(Comment $comment = NULL, $reply = FALSE) {
if ($comment) {
2008-09-08 21:37:21 +00:00
$regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
$regex .= '<a id="comment-' . $comment->id . '"(.*?)'; // Comment anchor.
$regex .= '<div(.*?)'; // Begin in comment div.
$regex .= $comment->subject . '(.*?)'; // Match subject.
$regex .= $comment->comment . '(.*?)'; // Match comment.
2009-07-28 10:09:25 +00:00
$regex .= '/s';
2008-09-08 21:37:21 +00:00
2010-08-05 23:53:39 +00:00
return (boolean)preg_match($regex, $this->drupalGetContent());
2008-09-08 21:37:21 +00:00
}
else {
return FALSE;
}
}
/**
2012-01-03 04:36:15 +00:00
* Deletes a comment.
2008-09-08 21:37:21 +00:00
*
2012-04-13 08:01:13 +00:00
* @param Comment $comment
2008-09-08 21:37:21 +00:00
* Comment to delete.
*/
2012-04-13 08:01:13 +00:00
function deleteComment(Comment $comment) {
2009-10-16 20:40:05 +00:00
$this->drupalPost('comment/' . $comment->id . '/delete', array(), t('Delete'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('The comment and all its replies have been deleted.'), t('Comment deleted.'));
2008-09-08 21:37:21 +00:00
}
/**
2012-01-03 04:36:15 +00:00
* Sets the value governing whether the subject field should be enabled.
2008-09-08 21:37:21 +00:00
*
* @param boolean $enabled
2012-01-03 04:36:15 +00:00
* Boolean specifying whether the subject field should be enabled.
2008-09-08 21:37:21 +00:00
*/
function setCommentSubject($enabled) {
$this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.');
}
/**
2012-01-03 04:36:15 +00:00
* Sets the value governing the previewing mode for the comment form.
2008-09-08 21:37:21 +00:00
*
2009-10-16 13:20:16 +00:00
* @param int $mode
2012-01-03 04:36:15 +00:00
* The preview mode: DRUPAL_DISABLED, DRUPAL_OPTIONAL or DRUPAL_REQUIRED.
2008-09-08 21:37:21 +00:00
*/
2009-10-16 13:20:16 +00:00
function setCommentPreview($mode) {
switch ($mode) {
case DRUPAL_DISABLED:
$mode_text = 'disabled';
break;
case DRUPAL_OPTIONAL:
$mode_text = 'optional';
break;
case DRUPAL_REQUIRED:
$mode_text = 'required';
break;
}
$this->setCommentSettings('comment_preview', $mode, 'Comment preview ' . $mode_text . '.');
2008-09-08 21:37:21 +00:00
}
/**
2012-01-03 04:36:15 +00:00
* Sets the value governing whether the comment form is on its own page.
2008-09-08 21:37:21 +00:00
*
* @param boolean $enabled
2012-01-03 04:36:15 +00:00
* TRUE if the comment form should be displayed on the same page as the
* comments; FALSE if it should be displayed on its own page.
2008-09-08 21:37:21 +00:00
*/
function setCommentForm($enabled) {
2009-06-19 13:03:53 +00:00
$this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
2008-09-08 21:37:21 +00:00
}
/**
2012-01-03 04:36:15 +00:00
* Sets the value governing restrictions on anonymous comments.
2008-09-08 21:37:21 +00:00
*
* @param integer $level
2012-01-03 04:36:15 +00:00
* The level of the contact information allowed for anonymous comments:
* - 0: No contact information allowed.
* - 1: Contact information allowed but not required.
* - 2: Contact information required.
2008-09-08 21:37:21 +00:00
*/
function setCommentAnonymous($level) {
$this->setCommentSettings('comment_anonymous', $level, 'Anonymous commenting set to level ' . $level . '.');
}
/**
2012-01-03 04:36:15 +00:00
* Sets the value specifying the default number of comments per page.
2008-09-08 21:37:21 +00:00
*
* @param integer $comments
* Comments per page value.
*/
function setCommentsPerPage($number) {
2009-06-19 13:03:53 +00:00
$this->setCommentSettings('comment_default_per_page', $number, 'Number of comments per page set to ' . $number . '.');
2008-09-08 21:37:21 +00:00
}
/**
2012-01-03 04:36:15 +00:00
* Sets a comment settings variable for the article content type.
2008-09-08 21:37:21 +00:00
*
* @param string $name
* Name of variable.
* @param string $value
* Value of variable.
* @param string $message
* Status message to display.
*/
function setCommentSettings($name, $value, $message) {
variable_set($name . '_article', $value);
2010-08-05 23:53:39 +00:00
$this->assertTrue(TRUE, t($message)); // Display status message.
2008-09-08 21:37:21 +00:00
}
/**
2012-01-03 04:36:15 +00:00
* Checks whether the commenter's contact information is displayed.
2008-09-08 21:37:21 +00:00
*
2012-01-03 04:36:15 +00:00
* @return boolean
* Contact info is available.
2008-09-08 21:37:21 +00:00
*/
function commentContactInfoAvailable() {
return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent());
}
/**
2012-01-03 04:36:15 +00:00
* Performs the specified operation on the specified comment.
2008-09-08 21:37:21 +00:00
*
* @param object $comment
* Comment to perform operation on.
* @param string $operation
* Operation to perform.
* @param boolean $aproval
* Operation is found on approval page.
*/
function performCommentOperation($comment, $operation, $approval = FALSE) {
$edit = array();
$edit['operation'] = $operation;
$edit['comments[' . $comment->id . ']'] = TRUE;
2009-07-30 19:24:21 +00:00
$this->drupalPost('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update'));
2008-09-08 21:37:21 +00:00
if ($operation == 'delete') {
$this->drupalPost(NULL, array(), t('Delete comments'));
2010-12-09 02:16:21 +00:00
$this->assertRaw(format_plural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), t('Operation "' . $operation . '" was performed on comment.'));
2008-09-08 21:37:21 +00:00
}
else {
2010-08-05 23:53:39 +00:00
$this->assertText(t('The update has been performed.'), t('Operation "' . $operation . '" was performed on comment.'));
2008-09-08 21:37:21 +00:00
}
}
/**
2012-01-03 04:36:15 +00:00
* Gets the comment ID for an unapproved comment.
2008-09-08 21:37:21 +00:00
*
* @param string $subject
* Comment subject to find.
2012-01-03 04:36:15 +00:00
*
2008-09-08 21:37:21 +00:00
* @return integer
* Comment id.
*/
function getUnapprovedComment($subject) {
2009-07-30 19:24:21 +00:00
$this->drupalGet('admin/content/comment/approval');
2008-09-08 21:37:21 +00:00
preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->drupalGetContent(), $match);
return $match[2];
}
}
class CommentInterfaceTest extends CommentHelperCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-09-08 21:37:21 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Comment interface',
'description' => 'Test comment user interfaces.',
'group' => 'Comment',
2008-09-08 21:37:21 +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
/**
2012-01-03 04:36:15 +00:00
* Tests the comment interface.
- 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 testCommentInterface() {
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2009-10-16 13:20:16 +00:00
// Set comments to have subject and preview disabled.
- 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($this->admin_user);
2009-10-16 13:20:16 +00:00
$this->setCommentPreview(DRUPAL_DISABLED);
2009-06-19 13:03:53 +00:00
$this->setCommentForm(TRUE);
- 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->setCommentSubject(FALSE);
2009-07-01 12:06:22 +00:00
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
- 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-16 13:20:16 +00:00
// Post comment #1 without subject or preview.
- 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($this->web_user);
2009-10-16 13:20:16 +00:00
$comment_text = $this->randomName();
$comment = $this->postComment($this->node, $comment_text);
$comment_loaded = comment_load($comment->id);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($comment), t('Comment found.'));
- 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 comments to have subject and preview to required.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$this->setCommentSubject(TRUE);
2009-10-16 13:20:16 +00:00
$this->setCommentPreview(DRUPAL_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
$this->drupalLogout();
2009-10-16 13:20:16 +00:00
// Create comment #2 that allows subject and requires preview.
- 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($this->web_user);
2008-09-19 03:11:53 +00:00
$subject_text = $this->randomName();
$comment_text = $this->randomName();
2009-10-16 13:20:16 +00:00
$comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
2008-10-14 20:34:56 +00:00
$comment_loaded = comment_load($comment->id);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($comment), t('Comment found.'));
- 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-09-19 03:11:53 +00:00
// Check comment display.
$this->drupalGet('node/' . $this->node->nid . '/' . $comment->id);
2010-08-05 23:53:39 +00:00
$this->assertText($subject_text, t('Individual comment subject found.'));
$this->assertText($comment_text, t('Individual comment body found.'));
2008-09-19 03:11:53 +00:00
2009-10-16 13:20:16 +00:00
// Set comments to have subject and preview to optional.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$this->setCommentSubject(TRUE);
$this->setCommentPreview(DRUPAL_OPTIONAL);
2011-05-14 02:16:34 +00:00
// Test changing the comment author to "Anonymous".
$this->drupalGet('comment/' . $comment->id . '/edit');
$comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => ''));
$comment_loaded = comment_load($comment->id);
$this->assertTrue(empty($comment_loaded->name) && $comment_loaded->uid == 0, t('Comment author successfully changed to anonymous.'));
// Test changing the comment author to an unverified user.
$random_name = $this->randomName();
$this->drupalGet('comment/' . $comment->id . '/edit');
$comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $random_name));
$this->drupalGet('node/' . $this->node->nid);
$this->assertText($random_name . ' (' . t('not verified') . ')', t('Comment author successfully changed to an unverified user.'));
// Test changing the comment author to a verified user.
$this->drupalGet('comment/' . $comment->id . '/edit');
$comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $this->web_user->name));
$comment_loaded = comment_load($comment->id);
$this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, t('Comment author successfully changed to a registered user.'));
2009-10-16 13:20:16 +00:00
$this->drupalLogout();
// Reply to comment #2 creating comment #3 with optional preview and no
// subject though field enabled.
$this->drupalLogin($this->web_user);
2008-05-30 07:30:53 +00:00
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
2010-08-05 23:53:39 +00:00
$this->assertText($subject_text, t('Individual comment-reply subject found.'));
$this->assertText($comment_text, t('Individual comment-reply body found.'));
2009-10-16 13:20:16 +00:00
$reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
2008-10-14 20:34:56 +00:00
$reply_loaded = comment_load($reply->id);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($reply, TRUE), t('Reply found.'));
$this->assertEqual($comment->id, $reply_loaded->pid, t('Pid of a reply to a comment is set correctly.'));
$this->assertEqual(rtrim($comment_loaded->thread, '/') . '.00/', $reply_loaded->thread, t('Thread of reply grows correctly.'));
2008-10-14 20:34:56 +00:00
2009-10-16 13:20:16 +00:00
// Second reply to comment #3 creating comment #4.
2008-10-14 20:34:56 +00:00
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
2010-08-05 23:53:39 +00:00
$this->assertText($subject_text, t('Individual comment-reply subject found.'));
$this->assertText($comment_text, t('Individual comment-reply body found.'));
2009-07-01 12:06:22 +00:00
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
2008-10-14 20:34:56 +00:00
$reply_loaded = comment_load($reply->id);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($reply, TRUE), t('Second reply found.'));
$this->assertEqual(rtrim($comment_loaded->thread, '/') . '.01/', $reply_loaded->thread, t('Thread of second reply grows correctly.'));
- 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
// Edit reply.
2009-10-16 20:40:05 +00:00
$this->drupalGet('comment/' . $reply->id . '/edit');
2009-07-01 12:06:22 +00:00
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($reply, TRUE), t('Modified reply found.'));
2008-06-24 17:01:33 +00:00
2008-06-18 16:06:42 +00:00
// Correct link count
$this->drupalGet('node');
2010-08-05 23:53:39 +00:00
$this->assertRaw('4 comments', t('Link to the 4 comments exist.'));
- 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-06-19 13:03:53 +00:00
// Confirm a new comment is posted to the correct page.
2008-06-14 16:02:50 +00:00
$this->setCommentsPerPage(2);
2009-07-01 12:06:22 +00:00
$comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($comment_new_page), t('Page one exists. %s'));
2009-09-29 15:31:17 +00:00
$this->drupalGet('node/' . $this->node->nid, array('query' => array('page' => 1)));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s'));
2008-06-14 16:02:50 +00:00
$this->setCommentsPerPage(50);
2008-09-19 03:00:10 +00:00
// Attempt to post to node with comments disabled.
2009-03-17 12:41:54 +00:00
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_HIDDEN));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->node, t('Article node created.'));
2008-09-19 03:00:10 +00:00
$this->drupalGet('comment/reply/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertText('This discussion is closed', t('Posting to node with comments disabled'));
$this->assertNoField('edit-comment', t('Comment body field found.'));
2008-09-19 03:00:10 +00:00
2008-11-11 16:49:38 +00:00
// Attempt to post to node with read-only comments.
2009-03-17 12:41:54 +00:00
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_CLOSED));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->node, t('Article node created.'));
2008-09-19 03:00:10 +00:00
$this->drupalGet('comment/reply/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertText('This discussion is closed', t('Posting to node with comments read-only'));
$this->assertNoField('edit-comment', t('Comment body field found.'));
2008-09-19 03:00:10 +00:00
// Attempt to post to node with comments enabled (check field names etc).
2009-03-17 12:41:54 +00:00
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->node, t('Article node created.'));
2008-09-19 03:00:10 +00:00
$this->drupalGet('comment/reply/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertNoText('This discussion is closed', t('Posting to node with comments enabled'));
$this->assertField('edit-comment-body-' . $langcode . '-0-value', t('Comment body field found.'));
2008-09-19 03:00:10 +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
// Delete comment and make sure that reply is also removed.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$this->deleteComment($comment);
2008-06-14 16:02:50 +00:00
$this->deleteComment($comment_new_page);
- 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-30 07:30:53 +00:00
$this->drupalGet('node/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertFalse($this->commentExists($comment), t('Comment not found.'));
$this->assertFalse($this->commentExists($reply, TRUE), t('Reply not found.'));
2008-09-08 21:37:21 +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
// Enabled comment form on node page.
$this->drupalLogin($this->admin_user);
$this->setCommentForm(TRUE);
$this->drupalLogout();
// Submit comment through node form.
$this->drupalLogin($this->web_user);
2008-05-30 07:30:53 +00:00
$this->drupalGet('node/' . $this->node->nid);
2009-07-01 12:06:22 +00:00
$form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($form_comment), t('Form comment found.'));
- 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
// Disable comment form on node page.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$this->setCommentForm(FALSE);
}
2010-11-06 11:15:10 +00:00
2012-01-13 13:59:42 +00:00
/**
* Tests new comment marker.
*/
public function testCommentNewCommentsIndicator() {
// Test if the right links are displayed when no comment is present for the
// node.
$this->drupalLogin($this->admin_user);
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
$this->drupalGet('node');
$this->assertNoLink(t('@count comments', array('@count' => 0)));
$this->assertNoLink(t('@count new comments', array('@count' => 0)));
$this->assertLink(t('Read more'));
$count = $this->xpath('//div[@id=:id]/div[@class=:class]/ul/li', array(':id' => 'node-' . $this->node->nid, ':class' => 'link-wrapper'));
$this->assertTrue(count($count) == 1, t('One child found'));
// Create a new comment. This helper function may be run with different
// comment settings so use comment_save() to avoid complex setup.
$comment = entity_create('comment', array(
'cid' => NULL,
'nid' => $this->node->nid,
'node_type' => $this->node->type,
'pid' => 0,
'uid' => $this->loggedInUser->uid,
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => ip_address(),
2012-03-08 15:10:59 +00:00
'langcode' => LANGUAGE_NOT_SPECIFIED,
'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())),
2012-01-13 13:59:42 +00:00
));
comment_save($comment);
$this->drupalLogout();
// Log in with 'web user' and check comment links.
$this->drupalLogin($this->web_user);
$this->drupalGet('node');
$this->assertLink(t('1 new comment'));
$this->clickLink(t('1 new comment'));
$this->assertRaw('<a id="new"></a>', t('Found "new" marker.'));
$this->assertTrue($this->xpath('//a[@id=:new]/following-sibling::a[1][@id=:comment_id]', array(':new' => 'new', ':comment_id' => 'comment-1')), t('The "new" anchor is positioned at the right comment.'));
// Test if "new comment" link is correctly removed.
$this->drupalGet('node');
$this->assertLink(t('1 comment'));
$this->assertLink(t('Read more'));
$this->assertNoLink(t('1 new comment'));
$this->assertNoLink(t('@count new comments', array('@count' => 0)));
$count = $this->xpath('//div[@id=:id]/div[@class=:class]/ul/li', array(':id' => 'node-' . $this->node->nid, ':class' => 'link-wrapper'));
$this->assertTrue(count($count) == 2, print_r($count, TRUE));
}
2012-01-31 05:00:17 +00:00
/**
* Tests CSS classes on comments.
*/
function testCommentClasses() {
// Create all permutations for comments, users, and nodes.
$parameters = array(
'node_uid' => array(0, $this->web_user->uid),
'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid),
'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
'user' => array('anonymous', 'authenticated', 'admin'),
);
$permutations = $this->generatePermutations($parameters);
foreach ($permutations as $case) {
// Create a new node.
$node = $this->drupalCreateNode(array('type' => 'article', 'uid' => $case['node_uid']));
// Add a comment.
$comment = entity_create('comment', array(
'nid' => $node->nid,
'uid' => $case['comment_uid'],
'status' => $case['comment_status'],
'subject' => $this->randomName(),
2012-03-08 15:10:59 +00:00
'language' => LANGUAGE_NOT_SPECIFIED,
'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())),
2012-01-31 05:00:17 +00:00
));
comment_save($comment);
// Adjust the current/viewing user.
switch ($case['user']) {
case 'anonymous':
$this->drupalLogout();
$case['user_uid'] = 0;
break;
case 'authenticated':
$this->drupalLogin($this->web_user);
$case['user_uid'] = $this->web_user->uid;
break;
case 'admin':
$this->drupalLogin($this->admin_user);
$case['user_uid'] = $this->admin_user->uid;
break;
}
// Request the node with the comment.
$this->drupalGet('node/' . $node->nid);
// Verify classes if the comment is visible for the current user.
if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
2012-03-11 12:21:59 +00:00
// Verify the by-anonymous class.
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "by-anonymous")]');
2012-01-31 05:00:17 +00:00
if ($case['comment_uid'] == 0) {
2012-03-11 12:21:59 +00:00
$this->assertTrue(count($comments) == 1, 'by-anonymous class found.');
2012-01-31 05:00:17 +00:00
}
else {
2012-03-11 12:21:59 +00:00
$this->assertFalse(count($comments), 'by-anonymous class not found.');
2012-01-31 05:00:17 +00:00
}
2012-03-11 12:21:59 +00:00
// Verify the by-node-author class.
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "by-node-author")]');
2012-01-31 05:00:17 +00:00
if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['node_uid']) {
2012-03-11 12:21:59 +00:00
$this->assertTrue(count($comments) == 1, 'by-node-author class found.');
2012-01-31 05:00:17 +00:00
}
else {
2012-03-11 12:21:59 +00:00
$this->assertFalse(count($comments), 'by-node-author class not found.');
2012-01-31 05:00:17 +00:00
}
2012-03-11 12:21:59 +00:00
// Verify the by-viewer class.
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "by-viewer")]');
2012-01-31 05:00:17 +00:00
if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['user_uid']) {
2012-03-11 12:21:59 +00:00
$this->assertTrue(count($comments) == 1, 'by-viewer class found.');
2012-01-31 05:00:17 +00:00
}
else {
2012-03-11 12:21:59 +00:00
$this->assertFalse(count($comments), 'by-viewer class not found.');
2012-01-31 05:00:17 +00:00
}
}
2012-03-11 12:21:59 +00:00
// Verify the unpublished class.
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "unpublished")]');
2012-01-31 05:00:17 +00:00
if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') {
2012-03-11 12:21:59 +00:00
$this->assertTrue(count($comments) == 1, 'unpublished class found.');
2012-01-31 05:00:17 +00:00
}
else {
2012-03-11 12:21:59 +00:00
$this->assertFalse(count($comments), 'unpublished class not found.');
2012-01-31 05:00:17 +00:00
}
2012-03-11 12:21:59 +00:00
// Verify the new class.
2012-01-31 05:00:17 +00:00
if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
2012-03-11 12:21:59 +00:00
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "new")]');
2012-01-31 05:00:17 +00:00
if ($case['user'] != 'anonymous') {
2012-03-11 12:21:59 +00:00
$this->assertTrue(count($comments) == 1, 'new class found.');
2012-01-31 05:00:17 +00:00
2012-03-11 12:21:59 +00:00
// Request the node again. The new class should disappear.
2012-01-31 05:00:17 +00:00
$this->drupalGet('node/' . $node->nid);
2012-03-11 12:21:59 +00:00
$comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "new")]');
$this->assertFalse(count($comments), 'new class not found.');
2012-01-31 05:00:17 +00:00
}
else {
2012-03-11 12:21:59 +00:00
$this->assertFalse(count($comments), 'new class not found.');
2012-01-31 05:00:17 +00:00
}
}
}
}
2010-11-06 11:15:10 +00:00
/**
* Tests the node comment statistics.
*/
function testCommentNodeCommentStatistics() {
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2010-11-06 11:15:10 +00:00
// Set comments to have subject and preview disabled.
$this->drupalLogin($this->admin_user);
$this->setCommentPreview(DRUPAL_DISABLED);
$this->setCommentForm(TRUE);
$this->setCommentSubject(FALSE);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
$this->drupalLogout();
// Creates a second user to post comments.
$this->web_user2 = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments'));
// Checks the initial values of node comment statistics with no comment.
$node = node_load($this->node->nid);
$this->assertEqual($node->last_comment_timestamp, $this->node->created, t('The initial value of node last_comment_timestamp is the node created date.'));
$this->assertEqual($node->last_comment_name, NULL, t('The initial value of node last_comment_name is NULL.'));
$this->assertEqual($node->last_comment_uid, $this->web_user->uid, t('The initial value of node last_comment_uid is the node uid.'));
$this->assertEqual($node->comment_count, 0, t('The initial value of node comment_count is zero.'));
// Post comment #1 as web_user2.
$this->drupalLogin($this->web_user2);
$comment_text = $this->randomName();
$comment = $this->postComment($this->node, $comment_text);
$comment_loaded = comment_load($comment->id);
// Checks the new values of node comment statistics with comment #1.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE);
$this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is NULL.'));
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is the comment #1 uid.'));
$this->assertEqual($node->comment_count, 1, t('The value of node comment_count is 1.'));
// Prepare for anonymous comment submission (comment approval enabled).
variable_set('user_register', USER_REGISTER_VISITORS);
$this->drupalLogin($this->admin_user);
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => FALSE,
));
// Ensure that the poster can leave some contact info.
$this->setCommentAnonymous('1');
$this->drupalLogout();
// Post comment #2 as anonymous (comment approval enabled).
$this->drupalGet('comment/reply/' . $this->node->nid);
$anonymous_comment = $this->postComment($this->node, $this->randomName(), '', TRUE);
$comment_unpublished_loaded = comment_load($anonymous_comment->id);
// Checks the new values of node comment statistics with comment #2 and
// ensure they haven't changed since the comment has not been moderated.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE);
$this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is still NULL.'));
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is still the comment #1 uid.'));
$this->assertEqual($node->comment_count, 1, t('The value of node comment_count is still 1.'));
// Prepare for anonymous comment submission (no approval required).
$this->drupalLogin($this->admin_user);
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
));
$this->drupalLogout();
// Post comment #3 as anonymous.
$this->drupalGet('comment/reply/' . $this->node->nid);
$anonymous_comment = $this->postComment($this->node, $this->randomName(), '', array('name' => $this->randomName()));
$comment_loaded = comment_load($anonymous_comment->id);
// Checks the new values of node comment statistics with comment #3.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE);
$this->assertEqual($node->last_comment_name, $comment_loaded->name, t('The value of node last_comment_name is the name of the anonymous user.'));
$this->assertEqual($node->last_comment_uid, 0, t('The value of node last_comment_uid is zero.'));
$this->assertEqual($node->comment_count, 2, t('The value of node comment_count is 2.'));
}
2011-01-02 23:54:05 +00:00
/**
* Tests comment links.
*
* The output of comment links depends on various environment conditions:
* - Various Comment module configuration settings, user registration
* settings, and user access permissions.
* - Whether the user is authenticated or not, and whether any comments exist.
*
* To account for all possible cases, this test creates permutations of all
* possible conditions and tests the expected appearance of comment links in
* each environment.
*/
function testCommentLinks() {
// Bartik theme alters comment links, so use a different theme.
2011-10-01 20:37:41 +00:00
theme_enable(array('stark'));
variable_set('theme_default', 'stark');
2011-01-02 23:54:05 +00:00
// Remove additional user permissions from $this->web_user added by setUp(),
// since this test is limited to anonymous and authenticated roles only.
user_role_delete(key($this->web_user->roles));
// Matrix of possible environmental conditions and configuration settings.
// See setEnvironment() for details.
$conditions = array(
'authenticated' => array(FALSE, TRUE),
'comment count' => array(FALSE, TRUE),
'access comments' => array(0, 1),
'post comments' => array(0, 1),
'form' => array(COMMENT_FORM_BELOW, COMMENT_FORM_SEPARATE_PAGE),
// USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL is irrelevant for this
// test; there is only a difference between open and closed registration.
'user_register' => array(USER_REGISTER_VISITORS, USER_REGISTER_ADMINISTRATORS_ONLY),
// @todo Complete test coverage for:
//'comments' => array(COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, COMMENT_NODE_HIDDEN),
//// COMMENT_ANONYMOUS_MUST_CONTACT is irrelevant for this test.
//'contact ' => array(COMMENT_ANONYMOUS_MAY_CONTACT, COMMENT_ANONYMOUS_MAYNOT_CONTACT),
);
$environments = $this->generatePermutations($conditions);
foreach ($environments as $info) {
$this->assertCommentLinks($info);
}
}
/**
* Re-configures the environment, module settings, and user permissions.
*
* @param $info
* An associative array describing the environment to setup:
* - Environment conditions:
* - authenticated: Boolean whether to test with $this->web_user or
* anonymous.
* - comment count: Boolean whether to test with a new/unread comment on
* $this->node or no comments.
* - Configuration settings:
* - form: COMMENT_FORM_BELOW or COMMENT_FORM_SEPARATE_PAGE.
* - user_register: USER_REGISTER_ADMINISTRATORS_ONLY or
* USER_REGISTER_VISITORS.
* - contact: COMMENT_ANONYMOUS_MAY_CONTACT or
* COMMENT_ANONYMOUS_MAYNOT_CONTACT.
* - comments: COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, or
* COMMENT_NODE_HIDDEN.
* - User permissions:
* These are granted or revoked for the user, according to the
* 'authenticated' flag above. Pass 0 or 1 as parameter values. See
* user_role_change_permissions().
* - access comments
* - post comments
* - skip comment approval
* - edit own comments
*/
function setEnvironment(array $info) {
static $current;
// Apply defaults to initial environment.
if (!isset($current)) {
$current = array(
'authenticated' => FALSE,
'comment count' => FALSE,
'form' => COMMENT_FORM_BELOW,
'user_register' => USER_REGISTER_VISITORS,
'contact' => COMMENT_ANONYMOUS_MAY_CONTACT,
'comments' => COMMENT_NODE_OPEN,
'access comments' => 0,
'post comments' => 0,
// Enabled by default, because it's irrelevant for this test.
'skip comment approval' => 1,
'edit own comments' => 0,
);
}
// Complete new environment with current environment.
$info = array_merge($current, $info);
// Change environment conditions.
if ($current['authenticated'] != $info['authenticated']) {
if ($this->loggedInUser) {
$this->drupalLogout();
}
else {
$this->drupalLogin($this->web_user);
}
}
if ($current['comment count'] != $info['comment count']) {
if ($info['comment count']) {
// Create a comment via CRUD API functionality, since
// $this->postComment() relies on actual user permissions.
2011-12-05 12:12:15 +00:00
$comment = entity_create('comment', array(
2011-01-02 23:54:05 +00:00
'cid' => NULL,
'nid' => $this->node->nid,
'node_type' => $this->node->type,
'pid' => 0,
'uid' => 0,
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => ip_address(),
2012-03-08 15:10:59 +00:00
'langcode' => LANGUAGE_NOT_SPECIFIED,
'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())),
2011-12-05 12:12:15 +00:00
));
2011-01-02 23:54:05 +00:00
comment_save($comment);
$this->comment = $comment;
// comment_num_new() relies on node_last_viewed(), so ensure that no one
// has seen the node of this comment.
db_delete('history')->condition('nid', $this->node->nid)->execute();
}
else {
$cids = db_query("SELECT cid FROM {comment}")->fetchCol();
comment_delete_multiple($cids);
unset($this->comment);
}
}
// Change comment settings.
variable_set('comment_form_location_' . $this->node->type, $info['form']);
variable_set('comment_anonymous_' . $this->node->type, $info['contact']);
if ($this->node->comment != $info['comments']) {
$this->node->comment = $info['comments'];
node_save($this->node);
}
// Change user settings.
variable_set('user_register', $info['user_register']);
// Change user permissions.
$rid = ($this->loggedInUser ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID);
$perms = array_intersect_key($info, array('access comments' => 1, 'post comments' => 1, 'skip comment approval' => 1, 'edit own comments' => 1));
user_role_change_permissions($rid, $perms);
// Output verbose debugging information.
// @see DrupalTestCase::error()
$t_form = array(
COMMENT_FORM_BELOW => 'below',
COMMENT_FORM_SEPARATE_PAGE => 'separate page',
);
$t_contact = array(
COMMENT_ANONYMOUS_MAY_CONTACT => 'optional',
COMMENT_ANONYMOUS_MAYNOT_CONTACT => 'disabled',
COMMENT_ANONYMOUS_MUST_CONTACT => 'required',
);
$t_comments = array(
COMMENT_NODE_OPEN => 'open',
COMMENT_NODE_CLOSED => 'closed',
COMMENT_NODE_HIDDEN => 'hidden',
);
$verbose = $info;
$verbose['form'] = $t_form[$info['form']];
$verbose['contact'] = $t_contact[$info['contact']];
$verbose['comments'] = $t_comments[$info['comments']];
$message = t('Changed environment:<pre>@verbose</pre>', array(
'@verbose' => var_export($verbose, TRUE),
));
$this->assert('debug', $message, 'Debug');
// Update current environment.
$current = $info;
return $info;
}
/**
2012-01-03 04:36:15 +00:00
* Asserts that comment links appear according to the passed environment.
2011-01-02 23:54:05 +00:00
*
* @param $info
* An associative array describing the environment to pass to
* setEnvironment().
*/
function assertCommentLinks(array $info) {
$info = $this->setEnvironment($info);
$nid = $this->node->nid;
foreach (array('', "node/$nid") as $path) {
$this->drupalGet($path);
// User is allowed to view comments.
if ($info['access comments']) {
if ($path == '') {
// In teaser view, a link containing the comment count is always
// expected.
if ($info['comment count']) {
$this->assertLink(t('1 comment'));
// For logged in users, a link containing the amount of new/unread
// comments is expected.
// See important note about comment_num_new() below.
if ($this->loggedInUser && isset($this->comment) && !isset($this->comment->seen)) {
$this->assertLink(t('1 new comment'));
$this->comment->seen = TRUE;
}
}
}
}
else {
$this->assertNoLink(t('1 comment'));
$this->assertNoLink(t('1 new comment'));
}
// comment_num_new() is based on node views, so comments are marked as
// read when a node is viewed, regardless of whether we have access to
// comments.
if ($path == "node/$nid" && $this->loggedInUser && isset($this->comment)) {
$this->comment->seen = TRUE;
}
// User is not allowed to post comments.
if (!$info['post comments']) {
$this->assertNoLink('Add new comment');
// Anonymous users should see a note to log in or register in case
// authenticated users are allowed to post comments.
// @see theme_comment_post_forbidden()
if (!$this->loggedInUser) {
if (user_access('post comments', $this->web_user)) {
// The note depends on whether users are actually able to register.
if ($info['user_register']) {
$this->assertText('Log in or register to post comments');
}
else {
$this->assertText('Log in to post comments');
}
}
else {
$this->assertNoText('Log in or register to post comments');
$this->assertNoText('Log in to post comments');
}
}
}
// User is allowed to post comments.
else {
$this->assertNoText('Log in or register to post comments');
// "Add new comment" is always expected, except when there are no
// comments or if the user cannot see them.
if ($path == "node/$nid" && $info['form'] == COMMENT_FORM_BELOW && (!$info['comment count'] || !$info['access comments'])) {
$this->assertNoLink('Add new comment');
}
else {
$this->assertLink('Add new comment');
2012-02-20 07:30:57 +00:00
// Verify that the "Add new comment" link points to the correct URL
// based on the comment form location configuration.
if ($info['form'] == COMMENT_FORM_SEPARATE_PAGE) {
$this->assertLinkByHref("comment/reply/$nid#comment-form", 0, 'Comment form link destination is on a separate page.');
$this->assertNoLinkByHref("node/$nid#comment-form");
}
else {
$this->assertLinkByHref("node/$nid#comment-form", 0, 'Comment form link destination is on node.');
$this->assertNoLinkByHref("comment/reply/$nid#comment-form");
}
2011-01-02 23:54:05 +00:00
}
// Also verify that the comment form appears according to the configured
// location.
if ($path == "node/$nid") {
$elements = $this->xpath('//form[@id=:id]', array(':id' => 'comment-form'));
if ($info['form'] == COMMENT_FORM_BELOW) {
$this->assertTrue(count($elements), t('Comment form found below.'));
}
else {
$this->assertFalse(count($elements), t('Comment form not found below.'));
}
}
}
}
}
2008-09-08 21:37:21 +00:00
}
2009-08-09 00:55:50 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests previewing comments.
2009-08-09 00:55:50 +00:00
*/
class CommentPreviewTest extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'Comment preview',
'description' => 'Test comment preview.',
'group' => 'Comment',
);
}
/**
2012-01-03 04:36:15 +00:00
* Tests comment preview.
2009-08-09 00:55:50 +00:00
*/
function testCommentPreview() {
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2010-01-07 05:23:52 +00:00
2009-08-09 00:55:50 +00:00
// As admin user, configure comment settings.
$this->drupalLogin($this->admin_user);
2010-02-13 19:34:54 +00:00
$this->setCommentPreview(DRUPAL_OPTIONAL);
2009-08-09 00:55:50 +00:00
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
$this->drupalLogout();
2012-03-02 04:53:40 +00:00
// Login as web user and add a signature and a user picture.
2009-08-09 00:55:50 +00:00
$this->drupalLogin($this->web_user);
2012-02-20 07:13:05 +00:00
variable_set('user_signatures', 1);
2012-03-02 04:53:40 +00:00
variable_set('user_pictures', 1);
2012-02-20 07:13:05 +00:00
$test_signature = $this->randomName();
$edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature. '</a>';
$edit['signature[format]'] = 'filtered_html';
2012-03-02 04:53:40 +00:00
$image = current($this->drupalGetTestFiles('image'));
$edit['files[picture_upload]'] = drupal_realpath($image->uri);
2012-02-20 07:13:05 +00:00
$this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
2012-03-02 04:53:40 +00:00
// As the web user, fill in the comment form and preview the comment.
2009-08-09 00:55:50 +00:00
$edit = array();
$edit['subject'] = $this->randomName(8);
2010-01-07 05:23:52 +00:00
$edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
2009-08-09 00:55:50 +00:00
$this->drupalPost('node/' . $this->node->nid, $edit, t('Preview'));
// Check that the preview is displaying the title and body.
2010-08-05 23:53:39 +00:00
$this->assertTitle(t('Preview comment | Drupal'), t('Page title is "Preview comment".'));
$this->assertText($edit['subject'], t('Subject displayed.'));
$this->assertText($edit['comment_body[' . $langcode . '][0][value]'], t('Comment displayed.'));
2009-08-09 00:55:50 +00:00
// Check that the title and body fields are displayed with the correct values.
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('subject', $edit['subject'], t('Subject field displayed.'));
$this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], t('Comment field displayed.'));
2012-02-20 07:13:05 +00:00
// Check that the signature is displaying with the correct text format.
$this->assertLink($test_signature);
2012-03-02 04:53:40 +00:00
// Check that the user picture is displayed.
2012-03-11 12:21:59 +00:00
$this->assertFieldByXPath("//div[contains(@class, 'preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
2009-08-09 00:55:50 +00:00
}
2009-10-08 08:16:54 +00:00
2009-08-09 00:55:50 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests comment edit, preview, and save.
2009-08-09 00:55:50 +00:00
*/
2010-12-28 18:19:23 +00:00
function testCommentEditPreviewSave() {
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2010-10-05 06:17:29 +00:00
$web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval'));
2009-08-09 00:55:50 +00:00
$this->drupalLogin($this->admin_user);
2010-02-13 19:34:54 +00:00
$this->setCommentPreview(DRUPAL_OPTIONAL);
2009-08-09 00:55:50 +00:00
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
2009-10-08 08:16:54 +00:00
2009-08-09 00:55:50 +00:00
$edit = array();
$edit['subject'] = $this->randomName(8);
2010-01-07 05:23:52 +00:00
$edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
2009-11-28 09:18:17 +00:00
$edit['name'] = $web_user->name;
2009-08-09 00:55:50 +00:00
$edit['date'] = '2008-03-02 17:23 +0300';
2010-12-28 18:19:23 +00:00
$raw_date = strtotime($edit['date']);
$expected_text_date = format_date($raw_date);
$expected_form_date = format_date($raw_date, 'custom', 'Y-m-d H:i O');
2010-01-07 05:23:52 +00:00
$comment = $this->postComment($this->node, $edit['subject'], $edit['comment_body[' . $langcode . '][0][value]'], TRUE);
2009-10-16 20:40:05 +00:00
$this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Preview'));
2009-10-08 08:16:54 +00:00
2009-08-09 00:55:50 +00:00
// Check that the preview is displaying the subject, comment, author and date correctly.
2010-08-05 23:53:39 +00:00
$this->assertTitle(t('Preview comment | Drupal'), t('Page title is "Preview comment".'));
$this->assertText($edit['subject'], t('Subject displayed.'));
$this->assertText($edit['comment_body[' . $langcode . '][0][value]'], t('Comment displayed.'));
$this->assertText($edit['name'], t('Author displayed.'));
2010-12-28 18:19:23 +00:00
$this->assertText($expected_text_date, t('Date displayed.'));
2009-08-09 00:55:50 +00:00
2010-12-28 18:19:23 +00:00
// Check that the subject, comment, author and date fields are displayed with the correct values.
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('subject', $edit['subject'], t('Subject field displayed.'));
$this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], t('Comment field displayed.'));
$this->assertFieldByName('name', $edit['name'], t('Author field displayed.'));
$this->assertFieldByName('date', $edit['date'], t('Date field displayed.'));
2010-12-28 18:19:23 +00:00
// Check that saving a comment produces a success message.
$this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Save'));
$this->assertText(t('Your comment has been posted.'), t('Comment posted.'));
// Check that the comment fields are correct after loading the saved comment.
$this->drupalGet('comment/' . $comment->id . '/edit');
$this->assertFieldByName('subject', $edit['subject'], t('Subject field displayed.'));
$this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], t('Comment field displayed.'));
$this->assertFieldByName('name', $edit['name'], t('Author field displayed.'));
$this->assertFieldByName('date', $expected_form_date, t('Date field displayed.'));
// Submit the form using the displayed values.
$displayed = array();
$displayed['subject'] = (string) current($this->xpath("//input[@id='edit-subject']/@value"));
$displayed['comment_body[' . $langcode . '][0][value]'] = (string) current($this->xpath("//textarea[@id='edit-comment-body-" . $langcode . "-0-value']"));
$displayed['name'] = (string) current($this->xpath("//input[@id='edit-name']/@value"));
$displayed['date'] = (string) current($this->xpath("//input[@id='edit-date']/@value"));
$this->drupalPost('comment/' . $comment->id . '/edit', $displayed, t('Save'));
// Check that the saved comment is still correct.
$comment_loaded = comment_load($comment->id);
$this->assertEqual($comment_loaded->subject, $edit['subject'], t('Subject loaded.'));
$this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], t('Comment body loaded.'));
$this->assertEqual($comment_loaded->name, $edit['name'], t('Name loaded.'));
$this->assertEqual($comment_loaded->created, $raw_date, t('Date loaded.'));
2009-08-09 00:55:50 +00:00
}
}
2012-01-03 04:36:15 +00:00
/**
* Tests anonymous commenting.
*/
2008-09-08 21:37:21 +00:00
class CommentAnonymous extends CommentHelperCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-09-08 21:37:21 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Anonymous comments',
'description' => 'Test anonymous comments.',
'group' => 'Comment',
2008-09-08 21:37:21 +00:00
);
}
2010-05-27 12:29:39 +00:00
function setUp() {
parent::setUp();
variable_set('user_register', USER_REGISTER_VISITORS);
}
- 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
/**
2012-01-03 04:36:15 +00:00
* Tests anonymous comment functionality.
- 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 testAnonymous() {
$this->drupalLogin($this->admin_user);
// Enabled anonymous user comments.
2009-10-08 08:16:54 +00:00
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => TRUE,
'post comments' => TRUE,
2010-10-05 06:17:29 +00:00
'skip comment approval' => TRUE,
2009-10-08 08:16:54 +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
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
$this->drupalLogout();
// Post anonymous comment without contact info.
$anonymous_comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($anonymous_comment1), t('Anonymous comment without contact info found.'));
- 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
// Allow contact info.
$this->drupalLogin($this->admin_user);
$this->setCommentAnonymous('1');
2008-11-21 14:48:59 +00:00
// Attempt to edit anonymous comment.
2009-10-16 20:40:05 +00:00
$this->drupalGet('comment/' . $anonymous_comment1->id . '/edit');
2008-11-21 14:48:59 +00:00
$edited_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($edited_comment, FALSE), t('Modified reply found.'));
- 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();
// Post anonymous comment with contact info (optional).
2008-05-30 07:30:53 +00:00
$this->drupalGet('comment/reply/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentContactInfoAvailable(), t('Contact information available.'));
- 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
$anonymous_comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($anonymous_comment2), t('Anonymous comment with contact info (optional) found.'));
- 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
2010-08-22 10:01:06 +00:00
// Ensure anonymous users cannot post in the name of registered users.
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2010-08-22 10:01:06 +00:00
$edit = array(
'name' => $this->admin_user->name,
'mail' => $this->randomName() . '@example.com',
'subject' => $this->randomName(),
2011-01-02 23:54:05 +00:00
"comment_body[$langcode][0][value]" => $this->randomName(),
2010-08-22 10:01:06 +00:00
);
$this->drupalPost('comment/reply/' . $this->node->nid, $edit, t('Save'));
$this->assertText(t('The name you used belongs to a registered 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
// Require contact info.
$this->drupalLogin($this->admin_user);
$this->setCommentAnonymous('2');
$this->drupalLogout();
// Try to post comment with contact info (required).
2008-05-30 07:30:53 +00:00
$this->drupalGet('comment/reply/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentContactInfoAvailable(), t('Contact information available.'));
- 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-10-16 13:20:16 +00:00
$anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
2010-08-05 23:53:39 +00:00
$this->assertText(t('E-mail field is required.'), t('E-mail required.')); // Name should have 'Anonymous' for value by default.
$this->assertFalse($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) not found.'));
- 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
// Post comment with contact info (required).
2010-04-22 10:12:25 +00:00
$author_name = $this->randomName();
$author_mail = $this->randomName() . '@example.com';
$anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), array('name' => $author_name, 'mail' => $author_mail));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) found.'));
- 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
2010-04-22 10:12:25 +00:00
// Make sure the user data appears correctly when editing the comment.
- 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($this->admin_user);
2010-04-22 10:12:25 +00:00
$this->drupalGet('comment/' . $anonymous_comment3->id . '/edit');
2010-08-05 23:53:39 +00:00
$this->assertRaw($author_name, t("The anonymous user's name is correct when editing the comment."));
$this->assertRaw($author_mail, t("The anonymous user's e-mail address is correct when editing the comment."));
2010-04-22 10:12:25 +00:00
// Unpublish comment.
- 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->performCommentOperation($anonymous_comment3, 'unpublish');
2009-07-30 19:24:21 +00:00
$this->drupalGet('admin/content/comment/approval');
2010-08-05 23:53:39 +00:00
$this->assertRaw('comments[' . $anonymous_comment3->id . ']', t('Comment was unpublished.'));
- 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
// Publish comment.
$this->performCommentOperation($anonymous_comment3, 'publish', TRUE);
2009-07-30 19:24:21 +00:00
$this->drupalGet('admin/content/comment');
2010-08-05 23:53:39 +00:00
$this->assertRaw('comments[' . $anonymous_comment3->id . ']', t('Comment was published.'));
- 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 comment.
$this->performCommentOperation($anonymous_comment3, 'delete');
2009-07-30 19:24:21 +00:00
$this->drupalGet('admin/content/comment');
2010-08-05 23:53:39 +00:00
$this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', t('Comment was deleted.'));
2009-10-08 08:16:54 +00:00
$this->drupalLogout();
- 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-06-03 16:30:20 +00:00
// Reset.
2009-10-08 08:16:54 +00:00
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => FALSE,
'post comments' => FALSE,
2010-10-05 06:17:29 +00:00
'skip comment approval' => FALSE,
2009-10-08 08:16:54 +00:00
));
2008-09-19 03:00:10 +00:00
2008-11-11 16:49:38 +00:00
// Attempt to view comments while disallowed.
2008-09-19 03:00:10 +00:00
// NOTE: if authenticated user has permission to post comments, then a
// "Login or register to post comments" type link may be shown.
$this->drupalGet('node/' . $this->node->nid);
2011-01-02 23:54:05 +00:00
$this->assertNoPattern('@<h2[^>]*>Comments</h2>@', t('Comments were not displayed.'));
2010-08-05 23:53:39 +00:00
$this->assertNoLink('Add new comment', t('Link to add comment was found.'));
2008-11-11 16:49:38 +00:00
2008-09-19 03:00:10 +00:00
// Attempt to view node-comment form while disallowed.
$this->drupalGet('comment/reply/' . $this->node->nid);
2011-01-02 23:54:05 +00:00
$this->assertText('You are not authorized to post comments', t('Error attempting to post comment.'));
2010-08-05 23:53:39 +00:00
$this->assertNoFieldByName('subject', '', t('Subject field not found.'));
2011-01-02 23:54:05 +00:00
$this->assertNoFieldByName("comment_body[$langcode][0][value]", '', t('Comment field not found.'));
2009-06-20 07:30:17 +00:00
2009-10-08 08:16:54 +00:00
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => TRUE,
'post comments' => FALSE,
2010-10-05 06:17:29 +00:00
'skip comment approval' => FALSE,
2009-10-08 08:16:54 +00:00
));
2009-06-20 07:30:17 +00:00
$this->drupalGet('node/' . $this->node->nid);
2011-01-02 23:54:05 +00:00
$this->assertPattern('@<h2[^>]*>Comments</h2>@', t('Comments were displayed.'));
2010-08-05 23:53:39 +00:00
$this->assertLink('Log in', 1, t('Link to log in was found.'));
$this->assertLink('register', 1, t('Link to register was found.'));
2011-01-02 23:54:05 +00:00
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => FALSE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
));
$this->drupalGet('node/' . $this->node->nid);
$this->assertNoPattern('@<h2[^>]*>Comments</h2>@', t('Comments were not displayed.'));
$this->assertFieldByName('subject', '', t('Subject field found.'));
$this->assertFieldByName("comment_body[$langcode][0][value]", '', t('Comment field found.'));
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $anonymous_comment3->id);
$this->assertText('You are not authorized to view comments', t('Error attempting to post reply.'));
$this->assertNoText($author_name, t('Comment not displayed.'));
2008-06-03 16:30:20 +00:00
}
2008-09-08 21:37:21 +00:00
}
2009-06-19 13:03:53 +00:00
/**
2012-01-03 04:36:15 +00:00
* Verifies pagination of comments.
2009-06-19 13:03:53 +00:00
*/
class CommentPagerTest extends CommentHelperCase {
public static function getInfo() {
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Comment paging settings',
'description' => 'Test paging of comments and their settings.',
'group' => 'Comment',
2009-06-19 13:03:53 +00:00
);
}
/**
2012-01-03 04:36:15 +00:00
* Confirms comment paging works correctly with flat and threaded comments.
2009-06-19 13:03:53 +00:00
*/
function testCommentPaging() {
$this->drupalLogin($this->admin_user);
// Set comment variables.
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
2010-02-13 19:34:54 +00:00
$this->setCommentPreview(DRUPAL_DISABLED);
2009-06-19 13:03:53 +00:00
// Create a node and three comments.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$comments = array();
2009-10-16 13:20:16 +00:00
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
2009-06-19 13:03:53 +00:00
2009-07-01 12:06:22 +00:00
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, t('Comment paging changed.'));
2009-06-19 13:03:53 +00:00
// Set comments to one per page so that we are able to test paging without
// needing to insert large numbers of comments.
$this->setCommentsPerPage(1);
// Check the first page of the node, and confirm the correct comments are
// shown.
$this->drupalGet('node/' . $node->nid);
2010-08-05 23:53:39 +00:00
$this->assertRaw(t('next'), t('Paging links found.'));
$this->assertTrue($this->commentExists($comments[0]), t('Comment 1 appears on page 1.'));
$this->assertFalse($this->commentExists($comments[1]), t('Comment 2 does not appear on page 1.'));
$this->assertFalse($this->commentExists($comments[2]), t('Comment 3 does not appear on page 1.'));
2009-06-19 13:03:53 +00:00
// Check the second page.
2009-09-29 15:31:17 +00:00
$this->drupalGet('node/' . $node->nid, array('query' => array('page' => 1)));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($comments[1]), t('Comment 2 appears on page 2.'));
$this->assertFalse($this->commentExists($comments[0]), t('Comment 1 does not appear on page 2.'));
$this->assertFalse($this->commentExists($comments[2]), t('Comment 3 does not appear on page 2.'));
2009-06-19 13:03:53 +00:00
// Check the third page.
2009-09-29 15:31:17 +00:00
$this->drupalGet('node/' . $node->nid, array('query' => array('page' => 2)));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($comments[2]), t('Comment 3 appears on page 3.'));
$this->assertFalse($this->commentExists($comments[0]), t('Comment 1 does not appear on page 3.'));
$this->assertFalse($this->commentExists($comments[1]), t('Comment 2 does not appear on page 3.'));
2009-06-19 13:03:53 +00:00
// Post a reply to the oldest comment and test again.
$replies = array();
$oldest_comment = reset($comments);
$this->drupalGet('comment/reply/' . $node->nid . '/' . $oldest_comment->id);
2009-10-16 13:20:16 +00:00
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
2009-06-19 13:03:53 +00:00
$this->setCommentsPerPage(2);
// We are still in flat view - the replies should not be on the first page,
// even though they are replies to the oldest comment.
2009-09-29 15:31:17 +00:00
$this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
2010-08-05 23:53:39 +00:00
$this->assertFalse($this->commentExists($reply, TRUE), t('In flat mode, reply does not appear on page 1.'));
2009-06-19 13:03:53 +00:00
// If we switch to threaded mode, the replies on the oldest comment
// should be bumped to the first page and comment 6 should be bumped
// to the second page.
2009-07-01 12:06:22 +00:00
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Switched to threaded mode.'));
2009-09-29 15:31:17 +00:00
$this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($reply, TRUE), t('In threaded mode, reply appears on page 1.'));
$this->assertFalse($this->commentExists($comments[1]), t('In threaded mode, comment 2 has been bumped off of page 1.'));
2009-06-19 13:03:53 +00:00
// If (# replies > # comments per page) in threaded expanded view,
// the overage should be bumped.
2009-10-16 13:20:16 +00:00
$reply2 = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
2009-09-29 15:31:17 +00:00
$this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
2010-08-05 23:53:39 +00:00
$this->assertFalse($this->commentExists($reply2, TRUE), t('In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.'));
2009-06-19 13:03:53 +00:00
$this->drupalLogout();
}
2009-12-08 06:33:11 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests comment ordering and threading.
2009-12-08 06:33:11 +00:00
*/
function testCommentOrderingThreading() {
$this->drupalLogin($this->admin_user);
// Set comment variables.
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
2010-02-13 19:34:54 +00:00
$this->setCommentPreview(DRUPAL_DISABLED);
2009-12-08 06:33:11 +00:00
// Display all the comments on the same page.
$this->setCommentsPerPage(1000);
// Create a node and three comments.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$comments = array();
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the second comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
$comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the first comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
$comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the last comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
$comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the second comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[3]->id);
$comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
// At this point, the comment tree is:
// - 0
// - 4
// - 1
// - 3
// - 6
// - 2
// - 5
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, t('Comment paging changed.'));
$expected_order = array(
0,
1,
2,
3,
4,
5,
6,
);
$this->drupalGet('node/' . $node->nid);
$this->assertCommentOrder($comments, $expected_order);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Switched to threaded mode.'));
$expected_order = array(
0,
4,
1,
3,
6,
2,
5,
);
$this->drupalGet('node/' . $node->nid);
$this->assertCommentOrder($comments, $expected_order);
}
/**
2012-01-03 04:36:15 +00:00
* Asserts that the comments are displayed in the correct order.
2009-12-08 06:33:11 +00:00
*
* @param $comments
* And array of comments.
* @param $expected_order
* An array of keys from $comments describing the expected order.
*/
function assertCommentOrder(array $comments, array $expected_order) {
$expected_cids = array();
// First, rekey the expected order by cid.
foreach ($expected_order as $key) {
$expected_cids[] = $comments[$key]->id;
}
2010-03-31 20:05:06 +00:00
$comment_anchors = $this->xpath('//a[starts-with(@id,"comment-")]');
2009-12-08 06:33:11 +00:00
$result_order = array();
foreach ($comment_anchors as $anchor) {
$result_order[] = substr($anchor['id'], 8);
}
2010-08-05 23:53:39 +00:00
return $this->assertIdentical($expected_cids, $result_order, t('Comment order: expected @expected, returned @returned.', array('@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order))));
2009-12-08 06:33:11 +00:00
}
2009-12-11 17:09:00 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests comment_new_page_count().
2009-12-11 17:09:00 +00:00
*/
function testCommentNewPageIndicator() {
$this->drupalLogin($this->admin_user);
// Set comment variables.
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
2010-02-13 19:34:54 +00:00
$this->setCommentPreview(DRUPAL_DISABLED);
2009-12-11 17:09:00 +00:00
// Set comments to one per page so that we are able to test paging without
// needing to insert large numbers of comments.
$this->setCommentsPerPage(1);
// Create a node and three comments.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$comments = array();
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
$comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the second comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
$comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the first comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
$comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the last comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
$comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
// At this point, the comment tree is:
// - 0
// - 4
// - 1
// - 3
// - 2
// - 5
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, t('Comment paging changed.'));
$expected_pages = array(
1 => 5, // Page of comment 5
2 => 4, // Page of comment 4
3 => 3, // Page of comment 3
4 => 2, // Page of comment 2
5 => 1, // Page of comment 1
6 => 0, // Page of comment 0
);
$node = node_load($node->nid);
foreach ($expected_pages as $new_replies => $expected_page) {
$returned = comment_new_page_count($node->comment_count, $new_replies, $node);
$returned_page = is_array($returned) ? $returned['page'] : 0;
2010-08-05 23:53:39 +00:00
$this->assertIdentical($expected_page, $returned_page, t('Flat mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
2009-12-11 17:09:00 +00:00
}
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Switched to threaded mode.'));
$expected_pages = array(
1 => 5, // Page of comment 5
2 => 1, // Page of comment 4
3 => 1, // Page of comment 4
4 => 1, // Page of comment 4
5 => 1, // Page of comment 4
6 => 0, // Page of comment 0
);
$node = node_load($node->nid);
foreach ($expected_pages as $new_replies => $expected_page) {
$returned = comment_new_page_count($node->comment_count, $new_replies, $node);
$returned_page = is_array($returned) ? $returned['page'] : 0;
2010-08-05 23:53:39 +00:00
$this->assertEqual($expected_page, $returned_page, t('Threaded mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
2009-12-11 17:09:00 +00:00
}
}
2009-06-19 13:03:53 +00:00
}
2010-12-01 00:19:18 +00:00
/**
* Tests comments with node access.
*
* See http://drupal.org/node/886752 -- verify there is no PostgreSQL error when
* viewing a node with threaded comments (a comment and a reply), if a node
* access module is in use.
*/
class CommentNodeAccessTest extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'Comment node access',
'description' => 'Test comment viewing with node access.',
'group' => 'Comment',
);
}
function setUp() {
DrupalWebTestCase::setUp('comment', 'search', 'node_access_test');
node_access_rebuild();
// Create users and test node.
$this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks'));
$this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments', 'node test view'));
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
}
/**
* Test that threaded comments can be viewed.
*/
function testThreadedCommentView() {
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2010-12-01 00:19:18 +00:00
// Set comments to have subject required and preview disabled.
$this->drupalLogin($this->admin_user);
$this->setCommentPreview(DRUPAL_DISABLED);
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
$this->drupalLogout();
// Post comment.
$this->drupalLogin($this->web_user);
$comment_text = $this->randomName();
$comment_subject = $this->randomName();
$comment = $this->postComment($this->node, $comment_text, $comment_subject);
$comment_loaded = comment_load($comment->id);
$this->assertTrue($this->commentExists($comment), t('Comment found.'));
// Check comment display.
$this->drupalGet('node/' . $this->node->nid . '/' . $comment->id);
$this->assertText($comment_subject, t('Individual comment subject found.'));
$this->assertText($comment_text, t('Individual comment body found.'));
// Reply to comment, creating second comment.
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
$reply_text = $this->randomName();
$reply_subject = $this->randomName();
$reply = $this->postComment(NULL, $reply_text, $reply_subject, TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($reply, TRUE), t('Reply found.'));
// Go to the node page and verify comment and reply are visible.
$this->drupalGet('node/' . $this->node->nid);
$this->assertText($comment_text);
$this->assertText($comment_subject);
$this->assertText($reply_text);
$this->assertText($reply_subject);
}
}
2012-01-03 04:36:15 +00:00
/**
* Tests comment approval functionality.
*/
2008-09-08 21:37:21 +00:00
class CommentApprovalTest extends CommentHelperCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-09-08 21:37:21 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Comment approval',
'description' => 'Test comment approval functionality.',
'group' => 'Comment',
2008-09-08 21:37:21 +00:00
);
}
2008-06-03 16:30:20 +00:00
/**
2009-07-30 19:24:21 +00:00
* Test comment approval functionality through admin/content/comment.
2008-06-03 16:30:20 +00:00
*/
function testApprovalAdminInterface() {
2008-12-30 16:43:20 +00:00
// Set anonymous comments to require approval.
2009-10-08 08:16:54 +00:00
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => TRUE,
'post comments' => TRUE,
2010-10-05 06:17:29 +00:00
'skip comment approval' => FALSE,
2009-10-08 08:16:54 +00:00
));
$this->drupalLogin($this->admin_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
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
2010-05-03 07:39:39 +00:00
// Test that the comments page loads correctly when there are no comments
$this->drupalGet('admin/content/comment');
$this->assertText(t('No comments available.'));
- 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();
// Post anonymous comment without contact info.
$subject = $this->randomName();
$body = $this->randomName();
2009-10-16 13:20:16 +00:00
$this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
2010-08-05 23:53:39 +00:00
$this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), t('Comment requires approval.'));
- 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-09-09 00:29:24 +00:00
// Get unapproved comment id.
- 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($this->admin_user);
2008-09-09 00:29:24 +00:00
$anonymous_comment4 = $this->getUnapprovedComment($subject);
2011-12-05 12:12:15 +00:00
$anonymous_comment4 = entity_create('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body));
- 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();
2010-08-05 23:53:39 +00:00
$this->assertFalse($this->commentExists($anonymous_comment4), t('Anonymous comment was not published.'));
- 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
// Approve comment.
$this->drupalLogin($this->admin_user);
$this->performCommentOperation($anonymous_comment4, 'publish', TRUE);
$this->drupalLogout();
2008-05-30 07:30:53 +00:00
$this->drupalGet('node/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.'));
2010-03-07 07:15:28 +00:00
// Post 2 anonymous comments without contact info.
$comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
$comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
// Publish multiple comments in one operation.
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/content/comment/approval');
2010-08-05 23:53:39 +00:00
$this->assertText(t('Unapproved comments (@count)', array('@count' => 2)), t('Two unapproved comments waiting for approval.'));
2010-03-07 07:15:28 +00:00
$edit = array(
"comments[{$comments[0]->id}]" => 1,
"comments[{$comments[1]->id}]" => 1,
);
$this->drupalPost(NULL, $edit, t('Update'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('Unapproved comments (@count)', array('@count' => 0)), t('All comments were approved.'));
2010-03-07 07:15:28 +00:00
// Delete multiple comments in one operation.
$edit = array(
'operation' => 'delete',
"comments[{$comments[0]->id}]" => 1,
"comments[{$comments[1]->id}]" => 1,
"comments[{$anonymous_comment4->id}]" => 1,
);
$this->drupalPost(NULL, $edit, t('Update'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('Are you sure you want to delete these comments and all their children?'), t('Confirmation required.'));
2010-03-07 07:15:28 +00:00
$this->drupalPost(NULL, $edit, t('Delete comments'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('No comments available.'), t('All comments were deleted.'));
2008-06-03 16:30:20 +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
2008-06-03 16:30:20 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests comment approval functionality through the node interface.
2008-06-03 16:30:20 +00:00
*/
function testApprovalNodeInterface() {
2008-12-30 16:43:20 +00:00
// Set anonymous comments to require approval.
2009-10-08 08:16:54 +00:00
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments' => TRUE,
'post comments' => TRUE,
2010-10-05 06:17:29 +00:00
'skip comment approval' => FALSE,
2009-10-08 08:16:54 +00:00
));
$this->drupalLogin($this->admin_user);
2008-06-03 16:30:20 +00:00
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
$this->drupalLogout();
// Post anonymous comment without contact info.
$subject = $this->randomName();
$body = $this->randomName();
2009-10-16 13:20:16 +00:00
$this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
2010-08-05 23:53:39 +00:00
$this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), t('Comment requires approval.'));
2008-06-03 16:30:20 +00:00
2008-12-30 16:43:20 +00:00
// Get unapproved comment id.
2008-06-03 16:30:20 +00:00
$this->drupalLogin($this->admin_user);
2008-09-09 00:29:24 +00:00
$anonymous_comment4 = $this->getUnapprovedComment($subject);
2011-12-05 12:12:15 +00:00
$anonymous_comment4 = entity_create('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body));
2008-06-03 16:30:20 +00:00
$this->drupalLogout();
2010-08-05 23:53:39 +00:00
$this->assertFalse($this->commentExists($anonymous_comment4), t('Anonymous comment was not published.'));
2008-06-03 16:30:20 +00:00
// Approve comment.
$this->drupalLogin($this->admin_user);
2010-03-28 07:00:30 +00:00
$this->drupalGet('comment/1/approve');
2010-08-05 23:53:39 +00:00
$this->assertResponse(403, t('Forged comment approval was denied.'));
2010-03-28 07:00:30 +00:00
$this->drupalGet('comment/1/approve', array('query' => array('token' => 'forged')));
2010-08-05 23:53:39 +00:00
$this->assertResponse(403, t('Forged comment approval was denied.'));
2009-05-24 17:39:35 +00:00
$this->drupalGet('node/' . $this->node->nid);
2008-06-03 16:30:20 +00:00
$this->clickLink(t('approve'));
$this->drupalLogout();
2009-05-24 17:39:35 +00:00
$this->drupalGet('node/' . $this->node->nid);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.'));
- 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-12-16 23:57:33 +00:00
2009-02-07 20:10:40 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests the Comment module blocks.
2009-02-07 20:10:40 +00:00
*/
class CommentBlockFunctionalTest extends CommentHelperCase {
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' => 'Comment blocks',
'description' => 'Test comment block functionality.',
'group' => 'Comment',
2008-12-16 23:57:33 +00:00
);
}
2009-02-07 20:10:40 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests the recent comments block.
2009-02-07 20:10:40 +00:00
*/
function testRecentCommentBlock() {
$this->drupalLogin($this->admin_user);
// Set the block to a region to confirm block is available.
$edit = array(
2010-08-30 00:22:03 +00:00
'blocks[comment_recent][region]' => 'sidebar_first',
2009-02-07 20:10:40 +00:00
);
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('The block settings have been updated.'), t('Block saved to first sidebar region.'));
2009-02-07 20:10:40 +00:00
// Set block title and variables.
$block = array(
'title' => $this->randomName(),
'comment_block_count' => 2,
);
2009-10-16 23:48:38 +00:00
$this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('The block configuration has been saved.'), t('Block saved.'));
2009-02-07 20:10:40 +00:00
// Add some test comments, one without a subject.
$comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
$comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
2009-10-16 13:20:16 +00:00
$comment3 = $this->postComment($this->node, $this->randomName());
2008-12-16 23:57:33 +00:00
2010-07-20 02:05:13 +00:00
// Test that a user without the 'access comments' permission cannot see the
// block.
2009-02-07 20:10:40 +00:00
$this->drupalLogout();
2010-07-20 02:05:13 +00:00
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
2011-09-29 03:29:59 +00:00
// drupalCreateNode() does not automatically flush content caches unlike
// posting a node from a node form.
cache_clear_all();
2009-02-07 20:10:40 +00:00
$this->drupalGet('');
2010-08-05 23:53:39 +00:00
$this->assertNoText($block['title'], t('Block was not found.'));
2010-07-20 02:05:13 +00:00
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
2009-02-07 20:10:40 +00:00
2010-07-20 02:05:13 +00:00
// Test that a user with the 'access comments' permission can see the
// block.
2009-02-07 20:10:40 +00:00
$this->drupalLogin($this->web_user);
$this->drupalGet('');
2010-08-05 23:53:39 +00:00
$this->assertText($block['title'], t('Block was found.'));
2009-02-07 20:10:40 +00:00
// Test the only the 2 latest comments are shown and in the proper order.
2010-08-05 23:53:39 +00:00
$this->assertNoText($comment1->subject, t('Comment not found in block.'));
$this->assertText($comment2->subject, t('Comment found in block.'));
$this->assertText($comment3->comment, t('Comment found in block.'));
$this->assertTrue(strpos($this->drupalGetContent(), $comment3->comment) < strpos($this->drupalGetContent(), $comment2->subject), t('Comments were ordered correctly in block.'));
2009-03-25 16:54:24 +00:00
// Set the number of recent comments to show to 10.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$block = array(
'comment_block_count' => 10,
);
2009-10-16 23:48:38 +00:00
$this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('The block configuration has been saved.'), t('Block saved.'));
2009-03-25 16:54:24 +00:00
2009-06-19 13:03:53 +00:00
// Post an additional comment.
$comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName());
// Test that all four comments are shown.
2010-08-05 23:53:39 +00:00
$this->assertText($comment1->subject, t('Comment found in block.'));
$this->assertText($comment2->subject, t('Comment found in block.'));
$this->assertText($comment3->comment, t('Comment found in block.'));
$this->assertText($comment4->subject, t('Comment found in block.'));
2009-06-19 13:03:53 +00:00
// Test that links to comments work when comments are across pages.
$this->setCommentsPerPage(1);
$this->drupalGet('');
$this->clickLink($comment1->subject);
2010-08-05 23:53:39 +00:00
$this->assertText($comment1->subject, t('Comment link goes to correct page.'));
2009-06-19 13:03:53 +00:00
$this->drupalGet('');
$this->clickLink($comment2->subject);
2010-08-05 23:53:39 +00:00
$this->assertText($comment2->subject, t('Comment link goes to correct page.'));
2009-06-19 13:03:53 +00:00
$this->clickLink($comment4->subject);
2010-08-05 23:53:39 +00:00
$this->assertText($comment4->subject, t('Comment link goes to correct page.'));
2009-06-19 13:03:53 +00:00
// Check that when viewing a comment page from a link to the comment, that
// rel="canonical" is added to the head of the document.
2010-08-05 23:53:39 +00:00
$this->assertRaw('<link rel="canonical"', t('Canonical URL was found in the HTML head'));
2008-12-16 23:57:33 +00:00
}
2009-02-07 20:10:40 +00:00
}
2008-12-16 23:57:33 +00:00
2009-02-07 20:10:40 +00:00
/**
2012-01-03 04:36:15 +00:00
* Unit tests for Comment module integration with RSS feeds.
2009-02-07 20:10:40 +00:00
*/
class CommentRSSUnitTest extends CommentHelperCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-07 20:10:40 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Comment RSS',
'description' => 'Test comments as part of an RSS feed.',
'group' => 'Comment',
2009-02-07 20:10:40 +00:00
);
}
2008-12-16 23:57:33 +00:00
2009-02-07 20:10:40 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests comments as part of an RSS feed.
2009-02-07 20:10:40 +00:00
*/
function testCommentRSS() {
2009-05-28 08:37:29 +00:00
// Find comment in RSS feed.
2009-02-07 20:10:40 +00:00
$this->drupalLogin($this->web_user);
$comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
$this->drupalGet('rss.xml');
$raw = '<comments>' . url('node/' . $this->node->nid, array('fragment' => 'comments', 'absolute' => TRUE)) . '</comments>';
2010-08-05 23:53:39 +00:00
$this->assertRaw($raw, t('Comments as part of RSS feed.'));
2009-05-28 08:37:29 +00:00
// Hide comments from RSS feed and check presence.
$this->node->comment = COMMENT_NODE_HIDDEN;
node_save($this->node);
$this->drupalGet('rss.xml');
2010-08-05 23:53:39 +00:00
$this->assertNoRaw($raw, t('Hidden comments is not a part of RSS feed.'));
2008-12-16 23:57:33 +00:00
}
}
2009-10-19 18:28:16 +00:00
2010-01-24 15:21:06 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests comment content rebuilding.
2010-01-24 15:21:06 +00:00
*/
class CommentContentRebuild extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'Comment Rebuild',
'description' => 'Test to make sure the comment content is rebuilt.',
'group' => 'Comment',
);
}
/**
2012-01-03 04:36:15 +00:00
* Tests the rebuilding of comment's content arrays on calling comment_view().
2010-01-24 15:21:06 +00:00
*/
function testCommentRebuild() {
// Update the comment settings so preview isn't required.
$this->drupalLogin($this->admin_user);
$this->setCommentSubject(TRUE);
$this->setCommentPreview(DRUPAL_OPTIONAL);
$this->drupalLogout();
// Log in as the web user and add the comment.
$this->drupalLogin($this->web_user);
$subject_text = $this->randomName();
$comment_text = $this->randomName();
$comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
$comment_loaded = comment_load($comment->id);
2010-08-05 23:53:39 +00:00
$this->assertTrue($this->commentExists($comment), t('Comment found.'));
2010-01-24 15:21:06 +00:00
// Add the property to the content array and then see if it still exists on build.
$comment_loaded->content['test_property'] = array('#value' => $this->randomString());
2010-01-25 10:40:00 +00:00
$built_content = comment_view($comment_loaded, $this->node);
2010-01-24 15:21:06 +00:00
// This means that the content was rebuilt as the added test property no longer exists.
2010-08-05 23:53:39 +00:00
$this->assertFalse(isset($built_content['test_property']), t('Comment content was emptied before being built.'));
2010-01-24 15:21:06 +00:00
}
2010-01-30 07:59:26 +00:00
}
2010-04-20 09:48:06 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests comment token replacement in strings.
2010-04-20 09:48:06 +00:00
*/
class CommentTokenReplaceTestCase extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'Comment token replacement',
'description' => 'Generates text using placeholders for dummy content to check comment token replacement.',
'group' => 'Comment',
);
}
/**
* Creates a comment, then tests the tokens generated from it.
*/
function testCommentTokenReplacement() {
2012-02-22 13:37:04 +00:00
global $language_interface;
2010-04-20 09:48:06 +00:00
$url_options = array(
'absolute' => TRUE,
2012-02-22 13:37:04 +00:00
'language' => $language_interface,
2010-04-20 09:48:06 +00:00
);
$this->drupalLogin($this->admin_user);
// Set comment variables.
$this->setCommentSubject(TRUE);
// Create a node and a comment.
$node = $this->drupalCreateNode(array('type' => 'article'));
$parent_comment = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
// Post a reply to the comment.
$this->drupalGet('comment/reply/' . $node->nid . '/' . $parent_comment->id);
$child_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
$comment = comment_load($child_comment->id);
$comment->homepage = 'http://example.org/';
// Add HTML to ensure that sanitation of some fields tested directly.
$comment->subject = '<blink>Blinking Comment</blink>';
$instance = field_info_instance('comment', 'body', 'comment_body');
// Generate and test sanitized tokens.
$tests = array();
$tests['[comment:cid]'] = $comment->cid;
$tests['[comment:hostname]'] = check_plain($comment->hostname);
$tests['[comment:name]'] = filter_xss($comment->name);
$tests['[comment:mail]'] = check_plain($this->admin_user->mail);
2010-07-07 17:00:43 +00:00
$tests['[comment:homepage]'] = check_url($comment->homepage);
2010-04-20 09:48:06 +00:00
$tests['[comment:title]'] = filter_xss($comment->subject);
2012-03-08 15:10:59 +00:00
$tests['[comment:body]'] = _text_sanitize($instance, LANGUAGE_NOT_SPECIFIED, $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0], 'value');
2010-04-20 09:48:06 +00:00
$tests['[comment:url]'] = url('comment/' . $comment->cid, $url_options + array('fragment' => 'comment-' . $comment->cid));
$tests['[comment:edit-url]'] = url('comment/' . $comment->cid . '/edit', $url_options);
2012-02-22 13:37:04 +00:00
$tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created, 2, $language_interface->langcode);
$tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed, 2, $language_interface->langcode);
2010-06-29 00:57:19 +00:00
$tests['[comment:parent:cid]'] = $comment->pid;
2010-04-20 09:48:06 +00:00
$tests['[comment:parent:title]'] = check_plain($parent_comment->subject);
2010-06-29 00:57:19 +00:00
$tests['[comment:node:nid]'] = $comment->nid;
2010-04-20 09:48:06 +00:00
$tests['[comment:node:title]'] = check_plain($node->title);
2010-06-29 00:57:19 +00:00
$tests['[comment:author:uid]'] = $comment->uid;
2010-04-20 09:48:06 +00:00
$tests['[comment:author:name]'] = check_plain($this->admin_user->name);
// Test to make sure that we generated something for each token.
2010-08-05 23:53:39 +00:00
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
2010-04-20 09:48:06 +00:00
foreach ($tests as $input => $expected) {
2012-02-22 13:37:04 +00:00
$output = token_replace($input, array('comment' => $comment), array('language' => $language_interface));
2011-03-01 01:36:37 +00:00
$this->assertEqual($output, $expected, t('Sanitized comment token %token replaced.', array('%token' => $input)));
2010-04-20 09:48:06 +00:00
}
// Generate and test unsanitized tokens.
$tests['[comment:hostname]'] = $comment->hostname;
$tests['[comment:name]'] = $comment->name;
$tests['[comment:mail]'] = $this->admin_user->mail;
$tests['[comment:homepage]'] = $comment->homepage;
$tests['[comment:title]'] = $comment->subject;
2012-03-08 15:10:59 +00:00
$tests['[comment:body]'] = $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['value'];
2010-04-20 09:48:06 +00:00
$tests['[comment:parent:title]'] = $parent_comment->subject;
$tests['[comment:node:title]'] = $node->title;
$tests['[comment:author:name]'] = $this->admin_user->name;
foreach ($tests as $input => $expected) {
2012-02-22 13:37:04 +00:00
$output = token_replace($input, array('comment' => $comment), array('language' => $language_interface, 'sanitize' => FALSE));
2011-03-01 01:36:37 +00:00
$this->assertEqual($output, $expected, t('Unsanitized comment token %token replaced.', array('%token' => $input)));
2010-04-20 09:48:06 +00:00
}
// Load node so comment_count gets computed.
$node = node_load($node->nid);
// Generate comment tokens for the node (it has 2 comments, both new).
$tests = array();
$tests['[node:comment-count]'] = 2;
$tests['[node:comment-count-new]'] = 2;
foreach ($tests as $input => $expected) {
2012-02-22 13:37:04 +00:00
$output = token_replace($input, array('node' => $node), array('language' => $language_interface));
2011-03-01 01:36:37 +00:00
$this->assertEqual($output, $expected, t('Node comment token %token replaced.', array('%token' => $input)));
2010-04-20 09:48:06 +00:00
}
}
}
2010-12-04 01:51:09 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests actions provided by the Comment module.
2010-12-04 01:51:09 +00:00
*/
class CommentActionsTestCase extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'Comment actions',
'description' => 'Test actions provided by the comment module.',
'group' => 'Comment',
);
}
/**
2012-01-03 04:36:15 +00:00
* Tests comment publish and unpublish actions.
2010-12-04 01:51:09 +00:00
*/
function testCommentPublishUnpublishActions() {
$this->drupalLogin($this->web_user);
$comment_text = $this->randomName();
$subject = $this->randomName();
$comment = $this->postComment($this->node, $comment_text, $subject);
$comment = comment_load($comment->id);
// Unpublish a comment (direct form: doesn't actually save the comment).
comment_unpublish_action($comment);
$this->assertEqual($comment->status, COMMENT_NOT_PUBLISHED, t('Comment was unpublished'));
$this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), t('Found watchdog message'));
$this->clearWatchdog();
// Unpublish a comment (indirect form: modify the comment in the database).
comment_unpublish_action(NULL, array('cid' => $comment->cid));
$this->assertEqual(comment_load($comment->cid)->status, COMMENT_NOT_PUBLISHED, t('Comment was unpublished'));
$this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), t('Found watchdog message'));
// Publish a comment (direct form: doesn't actually save the comment).
comment_publish_action($comment);
$this->assertEqual($comment->status, COMMENT_PUBLISHED, t('Comment was published'));
$this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), t('Found watchdog message'));
$this->clearWatchdog();
// Publish a comment (indirect form: modify the comment in the database).
comment_publish_action(NULL, array('cid' => $comment->cid));
$this->assertEqual(comment_load($comment->cid)->status, COMMENT_PUBLISHED, t('Comment was published'));
$this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), t('Found watchdog message'));
$this->clearWatchdog();
}
/**
2012-01-03 04:36:15 +00:00
* Verifies that a watchdog message has been entered.
2010-12-04 01:51:09 +00:00
*
* @param $watchdog_message
* The watchdog message.
* @param $variables
* The array of variables passed to watchdog().
* @param $message
* The assertion message.
*/
function assertWatchdogMessage($watchdog_message, $variables, $message) {
$status = (bool) db_query_range("SELECT 1 FROM {watchdog} WHERE message = :message AND variables = :variables", 0, 1, array(':message' => $watchdog_message, ':variables' => serialize($variables)))->fetchField();
return $this->assert($status, $message);
}
/**
2012-01-03 04:36:15 +00:00
* Clears watchdog.
2010-12-04 01:51:09 +00:00
*/
function clearWatchdog() {
db_truncate('watchdog')->execute();
}
}
2010-12-18 01:50:16 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests fields on comments.
2010-12-18 01:50:16 +00:00
*/
class CommentFieldsTest extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'Comment fields',
'description' => 'Tests fields on comments.',
'group' => 'Comment',
);
}
/**
* Tests that the default 'comment_body' field is correctly added.
*/
function testCommentDefaultFields() {
// Do not make assumptions on default node types created by the test
// install profile, and create our own.
$this->drupalCreateContentType(array('type' => 'test_node_type'));
// Check that the 'comment_body' field is present on all comment bundles.
$instances = field_info_instances('comment');
foreach (node_type_get_types() as $type_name => $info) {
$this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), t('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
// Delete the instance along the way.
field_delete_instance($instances['comment_node_' . $type_name]['comment_body']);
}
// Check that the 'comment_body' field is deleted.
$field = field_info_field('comment_body');
$this->assertTrue(empty($field), t('The comment_body field was deleted'));
// Create a new content type.
$type_name = 'test_node_type_2';
$this->drupalCreateContentType(array('type' => $type_name));
// Check that the 'comment_body' field exists and has an instance on the
// new comment bundle.
$field = field_info_field('comment_body');
$this->assertTrue($field, t('The comment_body field exists'));
$instances = field_info_instances('comment');
$this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), t('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
}
/**
2012-01-03 04:36:15 +00:00
* Tests that comment module works when enabled after a content module.
2010-12-18 01:50:16 +00:00
*/
function testCommentEnable() {
// Create a user to do module administration.
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
$this->drupalLogin($this->admin_user);
// Disable the comment module.
$edit = array();
$edit['modules[Core][comment][enable]'] = FALSE;
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
$this->resetAll();
$this->assertFalse(module_exists('comment'), t('Comment module disabled.'));
2011-08-27 08:09:58 +00:00
// Enable core content type modules (book, and poll).
2010-12-18 01:50:16 +00:00
$edit = array();
$edit['modules[Core][book][enable]'] = 'book';
$edit['modules[Core][poll][enable]'] = 'poll';
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
$this->resetAll();
// Now enable the comment module.
$edit = array();
$edit['modules[Core][comment][enable]'] = 'comment';
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
$this->resetAll();
$this->assertTrue(module_exists('comment'), t('Comment module enabled.'));
// Create nodes of each type.
$book_node = $this->drupalCreateNode(array('type' => 'book'));
$poll_node = $this->drupalCreateNode(array('type' => 'poll', 'active' => 1, 'runtime' => 0, 'choice' => array(array('chtext' => ''))));
$this->drupalLogout();
// Try to post a comment on each node. A failure will be triggered if the
// comment body is missing on one of these forms, due to postComment()
// asserting that the body is actually posted correctly.
$this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'post comments', 'skip comment approval'));
$this->drupalLogin($this->web_user);
$this->postComment($book_node, $this->randomName(), $this->randomName());
$this->postComment($poll_node, $this->randomName(), $this->randomName());
}
2011-06-30 06:51:49 +00:00
/**
2012-01-03 04:36:15 +00:00
* Tests that comment module works correctly with plain text format.
2011-06-30 06:51:49 +00:00
*/
function testCommentFormat() {
// Disable text processing for comments.
$this->drupalLogin($this->admin_user);
$edit = array('instance[settings][text_processing]' => 0);
$this->drupalPost('admin/structure/types/manage/article/comment/fields/comment_body', $edit, t('Save settings'));
// Post a comment without an explicit subject.
$this->drupalLogin($this->web_user);
$edit = array('comment_body[und][0][value]' => $this->randomName(8));
$this->drupalPost('node/' . $this->node->nid, $edit, t('Save'));
}
2010-12-18 01:50:16 +00:00
}
2012-03-02 04:32:55 +00:00
/**
* Tests comment threading.
*/
class CommentThreadingTestCase extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'Comment Threading',
'description' => 'Test to make sure the comment number increments properly.',
'group' => 'Comment',
);
}
/**
* Tests the comment threading.
*/
function testCommentThreading() {
2012-03-08 15:10:59 +00:00
$langcode = LANGUAGE_NOT_SPECIFIED;
2012-03-02 04:32:55 +00:00
// Set comments to have a subject with preview disabled.
$this->drupalLogin($this->admin_user);
$this->setCommentPreview(DRUPAL_DISABLED);
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
$this->drupalLogout();
// Create a node.
$this->drupalLogin($this->web_user);
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
// Post comment #1.
$this->drupalLogin($this->web_user);
$subject_text = $this->randomName();
$comment_text = $this->randomName();
$comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
$comment_loaded = comment_load($comment->id);
$this->assertTrue($this->commentExists($comment), 'Comment #1. Comment found.');
$this->assertEqual($comment_loaded->thread, '01/');
// Reply to comment #1 creating comment #2.
$this->drupalLogin($this->web_user);
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
$reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($reply, TRUE), 'Comment #2. Reply found.');
$this->assertEqual($reply_loaded->thread, '01.00/');
// Reply to comment #2 creating comment #3.
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($reply, TRUE), 'Comment #3. Second reply found.');
$this->assertEqual($reply_loaded->thread, '01.00.00/');
// Reply to comment #1 creating comment #4.
$this->drupalLogin($this->web_user);
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
$reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($comment), 'Comment #4. Third reply found.');
$this->assertEqual($reply_loaded->thread, '01.01/');
// Post comment #2 overall comment #5.
$this->drupalLogin($this->web_user);
$subject_text = $this->randomName();
$comment_text = $this->randomName();
$comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
$comment_loaded = comment_load($comment->id);
$this->assertTrue($this->commentExists($comment), 'Comment #5. Second comment found.');
$this->assertEqual($comment_loaded->thread, '02/');
// Reply to comment #5 creating comment #6.
$this->drupalLogin($this->web_user);
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
$reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($reply, TRUE), 'Comment #6. Reply found.');
$this->assertEqual($reply_loaded->thread, '02.00/');
// Reply to comment #6 creating comment #7.
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($reply, TRUE), 'Comment #7. Second reply found.');
$this->assertEqual($reply_loaded->thread, '02.00.00/');
// Reply to comment #5 creating comment #8.
$this->drupalLogin($this->web_user);
$this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
$reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
$reply_loaded = comment_load($reply->id);
$this->assertTrue($this->commentExists($comment), 'Comment #8. Third reply found.');
$this->assertEqual($reply_loaded->thread, '02.01/');
}
}