diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/comment.test | 484 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.test | 32 |
2 files changed, 295 insertions, 221 deletions
diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 4f28ea4f5..552bf9bd0 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -1,23 +1,12 @@ <?php // $Id$ -class CommentTestCase extends DrupalWebTestCase { +class CommentHelperCase extends DrupalWebTestCase { protected $admin_user; protected $web_user; protected $node; /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Comment functionality'), - 'description' => t('Thoroughly test comment administration and user interfaces.'), - 'group' => t('Comment'), - ); - } - - /** * Implementation of setUp(). */ function setUp() { @@ -33,6 +22,227 @@ class CommentTestCase extends DrupalWebTestCase { } /** + * Post comment. + * + * @param object $node Node to post comment on. + * @param string $subject Comment subject. + * @param string $comment Comment body. + * @param boolean $preview Should preview be required. + * @param mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info. + */ + function postComment($node, $subject, $comment, $preview = TRUE, $contact = NULL) { + $edit = array(); + $edit['subject'] = $subject; + $edit['comment'] = $comment; + + if ($contact !== NULL && is_array($contact)) { + $edit += $contact; + } + + if ($node !== NULL) { + $this->drupalGet('comment/reply/' . $node->nid); + } + + if ($preview) { + $this->assertNoFieldByName('op', t('Save'), t('Save button not found.')); // Preview required so no save button should be found. + $this->drupalPost(NULL, $edit, t('Preview')); + } + $this->drupalPost(NULL, $edit, t('Save')); + $match = array(); + // Get comment ID + preg_match('/#comment-([^"]+)/', $this->getURL(), $match); + + // Get comment. + if ($contact !== TRUE) { // If true then attempting to find error message. + $this->assertText($subject, 'Comment posted.'); + $this->assertTrue((!empty($match) && !empty($match[1])), t('Comment id found.')); + } + + if (isset($match[1])) { + return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment); + } + } + + /** + * Checks current page for specified comment. + * + * @param object $comment Comment object. + * @param boolean $reply The comment is a reply to another comment. + * @return boolean Comment found. + */ + function commentExists($comment, $reply = FALSE) { + if ($comment && is_object($comment)) { + $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. + $regex .= '<\/div>/s'; // Dot matches newlines and ensure that match doesn't bleed outside comment div. + + return (boolean)preg_match($regex, $this->drupalGetContent()); + } + else { + return FALSE; + } + } + + /** + * Delete comment. + * + * @param object $comment + * Comment to delete. + */ + function deleteComment($comment) { + $this->drupalPost('comment/delete/' . $comment->id, array(), t('Delete')); + $this->assertText(t('The comment and all its replies have been deleted.'), t('Comment deleted.')); + } + + /** + * Set comment subject setting. + * + * @param boolean $enabled + * Subject value. + */ + function setCommentSubject($enabled) { + $this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.'); + } + + /** + * Set comment preview setting. + * + * @param boolean $required + * Preview value. + */ + function setCommentPreview($required) { + $this->setCommentSettings('comment_preview', ($required ? '1' : '0'), 'Comment preview ' . ($required ? 'required' : 'optional') . '.'); + } + + /** + * Set comment form setting. + * + * @param boolean $enabled + * Form value. + */ + function setCommentForm($enabled) { + $this->setCommentSettings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.'); + } + + /** + * Set comment anonymous level setting. + * + * @param integer $level + * Anonymous level. + */ + function setCommentAnonymous($level) { + $this->setCommentSettings('comment_anonymous', $level, 'Anonymous commenting set to level ' . $level . '.'); + } + + /** + * Set the default number of comments per page. + * + * @param integer $comments + * Comments per page value. + */ + function setCommentsPerPage($number) { + $this->setCommentSettings('comment_default_per_page_article', $number, 'Number of comments per page set to ' . $number .'.'); + } + + /** + * Set comment setting for article content type. + * + * @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); + $this->assertTrue(TRUE, t($message)); // Display status message. + } + + /** + * Set anonymous comment setting. + * + * @param boolean $enabled + * Allow anonymous commenting. + * @param boolean $without_approval + * Allow anonymous commenting without approval. + */ + function setAnonymousUserComment($enabled, $without_approval) { + $edit = array(); + $edit['1[access comments]'] = $enabled; + $edit['1[post comments]'] = $enabled; + $edit['1[post comments without approval]'] = $without_approval; + $this->drupalPost('admin/user/permissions', $edit, t('Save permissions')); + $this->assertText(t('The changes have been saved.'), t('Anonymous user comments ' . ($enabled ? 'enabled' : 'disabled') . '.')); + } + + /** + * Check for contact info. + * + * @return boolean Contact info is available. + */ + function commentContactInfoAvailable() { + return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent()); + } + + /** + * Perform the specified operation on the specified comment. + * + * @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; + $this->drupalPost('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update')); + + if ($operation == 'delete') { + $this->drupalPost(NULL, array(), t('Delete comments')); + $this->assertText(t('The comments have been deleted.'), t('Operation "' . $operation . '" was performed on comment.')); + } + else { + $this->assertText(t('The update has been performed.'), t('Operation "' . $operation . '" was performed on comment.')); + } + } + + /** + * Get the comment ID for an unapproved comment. + * + * @param string $subject + * Comment subject to find. + * @return integer + * Comment id. + */ + function getUnapprovedComment($subject) { + $this->drupalGet('admin/content/comment/approval'); + preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->drupalGetContent(), $match); + + return $match[2]; + } +} + +class CommentInterfaceTest extends CommentHelperCase { + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Comment interface'), + 'description' => t('Test comment user interfaces.'), + 'group' => t('Comment'), + ); + } + + /** * Test comment interface. */ function testCommentInterface() { @@ -92,6 +302,20 @@ class CommentTestCase extends DrupalWebTestCase { $this->assertFalse($this->commentExists($comment), t('Comment not found.')); $this->assertFalse($this->commentExists($reply, TRUE), t('Reply not found.')); } +} + +class CommentNodePage extends CommentHelperCase { + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Comment on a node page'), + 'description' => t('Test comment form on a node page.'), + 'group' => t('Comment'), + ); + } /** * Test comment form on node page. @@ -114,6 +338,21 @@ class CommentTestCase extends DrupalWebTestCase { $this->setCommentForm(FALSE); } +} + +class CommentAnonymous extends CommentHelperCase { + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Comment on a node page'), + 'description' => t('Test anonymous comments.'), + 'group' => t('Comment'), + ); + } + /** * Test anonymous comment functionality. */ @@ -180,6 +419,20 @@ class CommentTestCase extends DrupalWebTestCase { $this->drupalLogin($this->admin_user); $this->setAnonymousUserComment(FALSE, FALSE); } +} + +class CommentApprovalTest extends CommentHelperCase { + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Comment approval'), + 'description' => t('Test comment approval functionality.'), + 'group' => t('Comment'), + ); + } /** * Test comment approval functionality through admin/content/comment. @@ -249,211 +502,4 @@ class CommentTestCase extends DrupalWebTestCase { $this->drupalGet('node/'. $this->node->nid); $this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.')); } - - /** - * Post comment. - * - * @param object $node Node to post comment on. - * @param string $subject Comment subject. - * @param string $comment Comment body. - * @param boolean $preview Should preview be required. - * @param mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info. - */ - function postComment($node, $subject, $comment, $preview = TRUE, $contact = NULL) { - $edit = array(); - $edit['subject'] = $subject; - $edit['comment'] = $comment; - - if ($contact !== NULL && is_array($contact)) { - $edit += $contact; - } - - if ($node !== NULL) { - $this->drupalGet('comment/reply/' . $node->nid); - } - - if ($preview) { - $this->assertNoFieldByName('op', t('Save'), t('Save button not found.')); // Preview required so no save button should be found. - $this->drupalPost(NULL, $edit, t('Preview')); - } - $this->drupalPost(NULL, $edit, t('Save')); - $match = array(); - // Get comment ID - preg_match('/#comment-([^"]+)/', $this->getURL(), $match); - - // Get comment. - if ($contact !== TRUE) { // If true then attempting to find error message. - $this->assertText($subject, 'Comment posted.'); - $this->assertTrue((!empty($match) && !empty($match[1])), t('Comment id found.')); - } - - if (isset($match[1])) { - return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment); - } - } - - /** - * Checks current page for specified comment. - * - * @param object $comment Comment object. - * @param boolean $reply The comment is a reply to another comment. - * @return boolean Comment found. - */ - function commentExists($comment, $reply = FALSE) { - if ($comment && is_object($comment)) { - $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. - $regex .= '<\/div>/s'; // Dot matches newlines and ensure that match doesn't bleed outside comment div. - - return (boolean)preg_match($regex, $this->drupalGetContent()); - } - else { - return FALSE; - } - } - - /** - * Delete comment. - * - * @param object $comment - * Comment to delete. - */ - function deleteComment($comment) { - $this->drupalPost('comment/delete/' . $comment->id, array(), t('Delete')); - $this->assertText(t('The comment and all its replies have been deleted.'), t('Comment deleted.')); - } - - /** - * Set comment subject setting. - * - * @param boolean $enabled - * Subject value. - */ - function setCommentSubject($enabled) { - $this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.'); - } - - /** - * Set comment preview setting. - * - * @param boolean $required - * Preview value. - */ - function setCommentPreview($required) { - $this->setCommentSettings('comment_preview', ($required ? '1' : '0'), 'Comment preview ' . ($required ? 'required' : 'optional') . '.'); - } - - /** - * Set comment form setting. - * - * @param boolean $enabled - * Form value. - */ - function setCommentForm($enabled) { - $this->setCommentSettings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.'); - } - - /** - * Set comment anonymous level setting. - * - * @param integer $level - * Anonymous level. - */ - function setCommentAnonymous($level) { - $this->setCommentSettings('comment_anonymous', $level, 'Anonymous commenting set to level ' . $level . '.'); - } - - /** - * Set the default number of comments per page. - * - * @param integer $comments - * Comments per page value. - */ - function setCommentsPerPage($number) { - $this->setCommentSettings('comment_default_per_page_article', $number, 'Number of comments per page set to ' . $number .'.'); - } - - /** - * Set comment setting for article content type. - * - * @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); - $this->assertTrue(TRUE, t($message)); // Display status message. - } - - /** - * Set anonymous comment setting. - * - * @param boolean $enabled - * Allow anonymous commenting. - * @param boolean $without_approval - * Allow anonymous commenting without approval. - */ - function setAnonymousUserComment($enabled, $without_approval) { - $edit = array(); - $edit['1[access comments]'] = $enabled; - $edit['1[post comments]'] = $enabled; - $edit['1[post comments without approval]'] = $without_approval; - $this->drupalPost('admin/user/permissions', $edit, t('Save permissions')); - $this->assertText(t('The changes have been saved.'), t('Anonymous user comments ' . ($enabled ? 'enabled' : 'disabled') . '.')); - } - - /** - * Check for contact info. - * - * @return boolean Contact info is available. - */ - function commentContactInfoAvailable() { - return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent()); - } - - /** - * Perform the specified operation on the specified comment. - * - * @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; - $this->drupalPost('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update')); - - if ($operation == 'delete') { - $this->drupalPost(NULL, array(), t('Delete comments')); - $this->assertText(t('The comments have been deleted.'), t('Operation "' . $operation . '" was performed on comment.')); - } - else { - $this->assertText(t('The update has been performed.'), t('Operation "' . $operation . '" was performed on comment.')); - } - } - - /** - * Get the comment ID for an unaproved comment. - * - * @param string $subject - * Comment subject to find. - * @return integer - * Comment id. - */ - function getUnaprovedComment($subject) { - $this->drupalGet('admin/content/comment/approval'); - preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->drupalGetContent(), $match); - - return $match[2]; - } } diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 82b3fd46e..e2e84398f 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -88,8 +88,8 @@ class TaxonomyTermFunctionsTestCase extends DrupalWebTestCase { */ function getInfo() { return array( - 'name' => t('Term functions'), - 'description' => t('Testing save/update/delete terms.'), + 'name' => t('Term no hierarchy'), + 'description' => t('Testing save/update/delete terms without a hierarchy.'), 'group' => t('Taxonomy') ); } @@ -161,6 +161,20 @@ class TaxonomyTermFunctionsTestCase extends DrupalWebTestCase { $edit['name'] = 0; taxonomy_save_vocabulary($edit); } +} + +class TaxonomyTermSingleTestCase extends DrupalWebTestCase { + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Term single hierarchy'), + 'description' => t('Testing save/update/delete terms in a single hierarchy.'), + 'group' => t('Taxonomy') + ); + } /** * Test single hierarchy terms. @@ -204,6 +218,20 @@ class TaxonomyTermFunctionsTestCase extends DrupalWebTestCase { $edit['name'] = 0; taxonomy_save_vocabulary($edit); } +} + +class TaxonomyTermMultipleTestCase extends DrupalWebTestCase { + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Term multiple hierarchy'), + 'description' => t('Testing save/update/delete terms in a multiple hierarchy.'), + 'group' => t('Taxonomy') + ); + } /** * Test multiple hierarchy terms. |