Skip to content
Snippets Groups Projects
Commit 0e788816 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #251235 by catch: first forum test clean-up.

parent 56842ef5
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// $Id$ // $Id$
class ForumTestCase extends DrupalWebTestCase { class ForumTestCase extends DrupalWebTestCase {
protected $big_user; protected $admin_user;
protected $own_user; protected $own_user;
protected $any_user; protected $any_user;
protected $nid_user; protected $nid_user;
...@@ -25,7 +25,7 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -25,7 +25,7 @@ class ForumTestCase extends DrupalWebTestCase {
function setUp() { function setUp() {
parent::setUp('taxonomy', 'comment', 'forum'); parent::setUp('taxonomy', 'comment', 'forum');
// Create users. // Create users.
$this->big_user = $this->drupalCreateUser(array('administer blocks', 'administer forums', 'administer menu', 'administer taxonomy', 'create forum content')); // 'access administration pages')); $this->admin_user = $this->drupalCreateUser(array('administer blocks', 'administer forums', 'administer menu', 'administer taxonomy', 'create forum content')); // 'access administration pages'));
$this->own_user = $this->drupalCreateUser(array('create forum content', 'edit own forum content', 'delete own forum content')); $this->own_user = $this->drupalCreateUser(array('create forum content', 'edit own forum content', 'delete own forum content'));
$this->any_user = $this->drupalCreateUser(array('create forum content', 'edit any forum content', 'delete any forum content', 'access administration pages')); $this->any_user = $this->drupalCreateUser(array('create forum content', 'edit any forum content', 'delete any forum content', 'access administration pages'));
$this->nid_user = $this->drupalCreateUser(array()); $this->nid_user = $this->drupalCreateUser(array());
...@@ -36,27 +36,27 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -36,27 +36,27 @@ class ForumTestCase extends DrupalWebTestCase {
*/ */
function testForum() { function testForum() {
// Do the admin tests. // Do the admin tests.
$this->doAdminTests($this->big_user); $this->doAdminTests($this->admin_user);
// Generate topics to populate the active forum block. // Generate topics to populate the active forum block.
$this->generateForumTopics($this->forum); $this->generateForumTopics($this->forum);
// Login the nid user to view the forum topics and generate an Active forum topics list (FAILS). // Login the nid user to view the forum topics and generate an active forum
// topics list.
$this->drupalLogin($this->nid_user); $this->drupalLogin($this->nid_user);
// View the forum topics.
$this->viewForumTopics($this->nids); $this->viewForumTopics($this->nids);
// Do basic tests for the any forum user. // Do basic tests for the any forum user.
$this->doBasicTests($this->any_user, TRUE); $this->doBasicTests($this->any_user, TRUE);
// Create another forum node for the any forum user. // Create another forum node for the any forum user.
// $node = $this->drupalCreateNode(array('type' => 'forum', 'uid' => $this->any_user->uid));
$node = $this->createForumTopic($this->forum, FALSE); $node = $this->createForumTopic($this->forum, FALSE);
// Do basic tests for the own forum user. // Do basic tests for the own forum user.
$this->doBasicTests($this->own_user, FALSE); $this->doBasicTests($this->own_user, FALSE);
// Verify the own forum user only has access to the forum view node. // Verify the own forum user only has access to the forum view node.
$this->verifyForums($this->any_user, $node, FALSE, 403); $this->verifyForums($this->any_user, $node, FALSE, 403);
// Create another forum node for the own forum user. // Create another forum node for the own forum user.
// $node = $this->drupalCreateNode(array('type' => 'forum', 'uid' => $this->own_user->uid));
$node = $this->createForumTopic($this->forum, FALSE); $node = $this->createForumTopic($this->forum, FALSE);
// Login the any forum user. // Login the any forum user.
...@@ -79,7 +79,7 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -79,7 +79,7 @@ class ForumTestCase extends DrupalWebTestCase {
$edit['forum_active[region]'] = 'sidebar_second'; $edit['forum_active[region]'] = 'sidebar_second';
$this->drupalPost('admin/structure/block', $edit, t('Save blocks')); $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this->assertResponse(200); $this->assertResponse(200);
$this->assertText(t('The block settings have been updated.'), t('[Active forum topics] Forum block was enabled')); $this->assertText(t('The block settings have been updated.'), t('Active forum topics forum block was enabled'));
// Enable the new forum block. // Enable the new forum block.
$edit = array(); $edit = array();
...@@ -153,9 +153,13 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -153,9 +153,13 @@ class ForumTestCase extends DrupalWebTestCase {
/** /**
* Create a forum container or a forum. * Create a forum container or a forum.
* *
* @param string $type Forum type (forum container or forum). * @param $type
* @param integer $parent Forum parent (default = 0 = a root forum; >0 = a forum container or another forum). * Forum type (forum container or forum).
* @return object Taxonomy_term_data created. * @param $parent
* Forum parent (default = 0 = a root forum; >0 = a forum container or
* another forum).
* @return
* taxonomy_term_data created.
*/ */
function createForum($type, $parent = 0) { function createForum($type, $parent = 0) {
// Generate a random name/description. // Generate a random name/description.
...@@ -190,10 +194,11 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -190,10 +194,11 @@ class ForumTestCase extends DrupalWebTestCase {
/** /**
* Delete a forum. * Delete a forum.
* *
* @param integer $tid Forum id. * @param $tid
* The forum ID.
*/ */
function deleteForum($tid) { function deleteForum($tid) {
// Delete the forum id. // Delete the forum.
$this->drupalPost('admin/structure/forum/edit/forum/' . $tid, array(), t('Delete')); $this->drupalPost('admin/structure/forum/edit/forum/' . $tid, array(), t('Delete'));
$this->drupalPost(NULL, NULL, t('Delete')); $this->drupalPost(NULL, NULL, t('Delete'));
...@@ -205,8 +210,10 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -205,8 +210,10 @@ class ForumTestCase extends DrupalWebTestCase {
/** /**
* Run basic tests on the indicated user. * Run basic tests on the indicated user.
* *
* @param object $user The logged in user. * @param $user
* @param boolean $admin User has 'access administration pages' privilege. * The logged in user.
* @param $admin
* User has 'access administration pages' privilege.
*/ */
private function doBasicTests($user, $admin) { private function doBasicTests($user, $admin) {
// Login the user. // Login the user.
...@@ -230,7 +237,10 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -230,7 +237,10 @@ class ForumTestCase extends DrupalWebTestCase {
// Generate a random subject/body. // Generate a random subject/body.
$title = $this->randomName(20); $title = $this->randomName(20);
$body = $this->randomName(200); $body = $this->randomName(200);
$tid = $forum['tid']; // Without this being set, post variable equals the first non-blank in select items list.
// Without this being set, post variable equals the first non-blank in
// select items list.
$tid = $forum['tid'];
$langcode = FIELD_LANGUAGE_NONE; $langcode = FIELD_LANGUAGE_NONE;
$edit = array( $edit = array(
...@@ -239,12 +249,11 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -239,12 +249,11 @@ class ForumTestCase extends DrupalWebTestCase {
'taxonomy[1]' => $tid 'taxonomy[1]' => $tid
); );
// TODO The taxonomy select value is set by drupal code when the tid is part of the url. // TODO The taxonomy select value is set by drupal code when the tid is part
// However, unless a tid is passed in the edit array, when drupalPost runs, the select value is not preserved. // of the url. However, unless a tid is passed in the edit array, when
// Instead, the post variables seem to pick up the first non-blank value in the select list. // drupalPost() runs, the select value is not preserved. Instead, the post
// variables seem to pick up the first non-blank value in the select list.
// Create forum topic. // Create forum topic.
// $this->drupalPost('node/add/forum/' . $forum['tid'], $edit, t('Save'));
$this->drupalPost('node/add/forum/', $edit, t('Save')); $this->drupalPost('node/add/forum/', $edit, t('Save'));
$type = t('Forum topic'); $type = t('Forum topic');
if ($container) { if ($container) {
...@@ -270,12 +279,16 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -270,12 +279,16 @@ class ForumTestCase extends DrupalWebTestCase {
} }
/** /**
* Verify the logged in user has the desired access to the various forum nodes. * Verify the logged in user has access to a forum nodes.
* *
* @param object $node_user The user who creates the node. * @param $node_user
* @param object $node Node. * The user who creates the node.
* @param boolean $admin User has 'access administration pages' privilege. * @param $node
* @param integer $response HTTP response code. * The node being checked.
* @param $admin
* Boolean to indicate whether the user can 'access administration pages'.
* @param $response
* The exptected HTTP response code.
*/ */
private function verifyForums($node_user, $node, $admin, $response = 200) { private function verifyForums($node_user, $node, $admin, $response = 200) {
$crumb = '›'; $crumb = '›';
...@@ -294,8 +307,6 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -294,8 +307,6 @@ class ForumTestCase extends DrupalWebTestCase {
// Verify the forum blocks were displayed. // Verify the forum blocks were displayed.
$this->drupalGet(''); $this->drupalGet('');
$this->assertResponse(200); $this->assertResponse(200);
// This block never seems to display?
// $this->assertText(t('Active forum topics'), t('[Active forum topics] Forum block was displayed'));
$this->assertText(t('New forum topics'), t('[New forum topics] Forum block was displayed')); $this->assertText(t('New forum topics'), t('[New forum topics] Forum block was displayed'));
// View forum container page. // View forum container page.
...@@ -324,7 +335,8 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -324,7 +335,8 @@ class ForumTestCase extends DrupalWebTestCase {
$edit['title'] = 'node/' . $node->nid; $edit['title'] = 'node/' . $node->nid;
$langcode = FIELD_LANGUAGE_NONE; $langcode = FIELD_LANGUAGE_NONE;
$edit["body[$langcode][0][value]"] = $this->randomName(256); $edit["body[$langcode][0][value]"] = $this->randomName(256);
$edit['taxonomy[1]'] = $this->root_forum['tid']; // Assumes the topic is initially associated with $forum. // Assume the topic is initially associated with $forum.
$edit['taxonomy[1]'] = $this->root_forum['tid'];
$edit['shadow'] = TRUE; $edit['shadow'] = TRUE;
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit['title'])), t('Forum node was edited')); $this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit['title'])), t('Forum node was edited'));
...@@ -346,7 +358,8 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -346,7 +358,8 @@ class ForumTestCase extends DrupalWebTestCase {
/** /**
* Verify display of forum page. * Verify display of forum page.
* *
* @param array $forum Forum array (a row from taxonomy_term_data table). * @param $forum
* A row from taxonomy_term_data table in array.
*/ */
private function verifyForumView($forum, $parent = NULL) { private function verifyForumView($forum, $parent = NULL) {
$crumb = '›'; $crumb = '›';
...@@ -379,7 +392,12 @@ class ForumTestCase extends DrupalWebTestCase { ...@@ -379,7 +392,12 @@ class ForumTestCase extends DrupalWebTestCase {
/** /**
* View forum topics to test display of active forum block. * View forum topics to test display of active forum block.
* *
* @param array $nids Forum node id array. * @todo The logic here is completely incorrect, since the active
* forum topics block is determined by comments on the node, not by views.
* @todo DIE
*
* @param $nids
* An array of forum node IDs.
*/ */
private function viewForumTopics($nids) { private function viewForumTopics($nids) {
$crumb = '›'; $crumb = '›';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment