ForumTest.php 23.8 KB
Newer Older
1 2
<?php

3 4
/**
 * @file
5
 * Tests for forum.module.
6 7
 */

8 9
namespace Drupal\forum\Tests;

10
use Drupal\node\Node;
11
use Drupal\simpletest\WebTestBase;
12

13 14 15
/**
 * Provides automated tests for the Forum module.
 */
16
class ForumTest extends WebTestBase {
17 18 19 20

  /**
   * A user with various administrative privileges.
   */
21
  protected $admin_user;
22 23 24 25

  /**
   * A user that can create forum topics and edit its own topics.
   */
26
  protected $edit_own_topics_user;
27 28 29 30

  /**
   * A user that can create, edit, and delete forum topics.
   */
31
  protected $edit_any_topics_user;
32 33 34 35

  /**
   * A user with no special privileges.
   */
36
  protected $web_user;
37 38 39 40

  /**
   * An array representing a container.
   */
41
  protected $container;
42 43 44 45

  /**
   * An array representing a forum.
   */
46
  protected $forum;
47 48 49 50

  /**
   * An array representing a root forum.
   */
51
  protected $root_forum;
52 53 54 55

  /**
   * An array of forum topic node IDs.
   */
56 57
  protected $nids;

58
  public static function getInfo() {
59
    return array(
60 61 62
      'name' => 'Forum functionality',
      'description' => 'Create, view, edit, delete, and change forum entries and verify its consistency in the database.',
      'group' => 'Forum',
63 64 65 66
    );
  }

  function setUp() {
67
    parent::setUp(array('taxonomy', 'comment', 'forum', 'node', 'block', 'menu', 'help'));
68
    // Create users.
69 70
    $this->admin_user = $this->drupalCreateUser(array(
      'access administration pages',
71
      'administer modules',
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
      'administer blocks',
      'administer forums',
      'administer menu',
      'administer taxonomy',
      'create forum content',
    ));
    $this->edit_any_topics_user = $this->drupalCreateUser(array(
      'access administration pages',
      'create forum content',
      'edit any forum content',
      'delete any forum content',
    ));
    $this->edit_own_topics_user = $this->drupalCreateUser(array(
      'create forum content',
      'edit own forum content',
      'delete own forum content',
    ));
89
    $this->web_user = $this->drupalCreateUser();
90 91
  }

92
  /**
93
   * Tests disabling and re-enabling the Forum module.
94 95 96 97
   */
  function testEnableForumField() {
    $this->drupalLogin($this->admin_user);

98
    // Disable the Forum module.
99 100 101 102
    $edit = array();
    $edit['modules[Core][forum][enable]'] = FALSE;
    $this->drupalPost('admin/modules', $edit, t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
103
    system_list_reset();
104 105
    $this->assertFalse(module_exists('forum'), t('Forum module is not enabled.'));

106
    // Attempt to re-enable the Forum module and ensure it does not try to
107 108 109 110 111
    // recreate the taxonomy_forums field.
    $edit = array();
    $edit['modules[Core][forum][enable]'] = 'forum';
    $this->drupalPost('admin/modules', $edit, t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
112
    system_list_reset();
113 114 115
    $this->assertTrue(module_exists('forum'), t('Forum module is enabled.'));
  }

116
  /**
117
   * Tests forum functionality through the admin and user interfaces.
118 119
   */
  function testForum() {
120 121 122 123 124
    //Check that the basic forum install creates a default forum topic
    $this->drupalGet("/forum");
    // Look for the "General discussion" default forum
    $this->assertText(t("General discussion"), "Found the default forum at the /forum listing");

125
    // Do the admin tests.
126
    $this->doAdminTests($this->admin_user);
127 128 129
    // Generate topics to populate the active forum block.
    $this->generateForumTopics($this->forum);

130 131 132
    // Login an unprivileged user to view the forum topics and generate an
    // active forum topics list.
    $this->drupalLogin($this->web_user);
133 134 135 136
    // Verify that this user is shown a message that they may not post content.
    $this->drupalGet('forum/' . $this->forum['tid']);
    $this->assertText(t('You are not allowed to post new content in the forum'), "Authenticated user without permission to post forum content is shown message in local tasks to that effect.");

137 138
    $this->viewForumTopics($this->nids);

139 140 141 142 143 144 145 146 147 148 149 150 151 152
    // Log in, and do basic tests for a user with permission to edit any forum
    // content.
    $this->doBasicTests($this->edit_any_topics_user, TRUE);
    // Create a forum node authored by this user.
    $any_topics_user_node = $this->createForumTopic($this->forum, FALSE);

    // Log in, and do basic tests for a user with permission to edit only its
    // own forum content.
    $this->doBasicTests($this->edit_own_topics_user, FALSE);
    // Create a forum node authored by this user.
    $own_topics_user_node = $this->createForumTopic($this->forum, FALSE);
    // Verify that this user cannot edit forum content authored by another user.
    $this->verifyForums($this->edit_any_topics_user, $any_topics_user_node, FALSE, 403);

153 154 155 156 157 158
    // Verify that this user is shown a local task to add new forum content.
    $this->drupalGet('forum');
    $this->assertLink(t('Add new Forum topic'));
    $this->drupalGet('forum/' . $this->forum['tid']);
    $this->assertLink(t('Add new Forum topic'));

159 160 161 162
    // Login a user with permission to edit any forum content.
    $this->drupalLogin($this->edit_any_topics_user);
    // Verify that this user can edit forum content authored by another user.
    $this->verifyForums($this->edit_own_topics_user, $own_topics_user_node, TRUE);
163 164 165

    // Verify the topic and post counts on the forum page.
    $this->drupalGet('forum');
166 167 168 169 170 171 172 173 174 175 176 177

    // Verify row for testing forum.
    $forum_arg = array(':forum' => 'forum-list-' . $this->forum['tid']);

    // Topics cell contains number of topics and number of unread topics.
    $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="topics"]', $forum_arg);
    $topics = $this->xpath($xpath);
    $topics = trim($topics[0]);
    $this->assertEqual($topics, '6', t('Number of topics found.'));

    // Verify the number of unread topics.
    $unread_topics = _forum_topics_unread($this->forum['tid'], $this->edit_any_topics_user->uid);
178
    $unread_topics = format_plural($unread_topics, '1 new post', '@count new posts');
179 180
    $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="topics"]//a', $forum_arg);
    $this->assertFieldByXPath($xpath, $unread_topics, t('Number of unread topics found.'));
181 182 183
    // Verify that the forum name is in the unread topics text.
    $xpath = $this->buildXPathQuery('//tr[@id=:forum]//em[@class="placeholder"]', $forum_arg);
    $this->assertFieldByXpath($xpath, $this->forum['name'], t('Forum name found in unread topics text.'));
184 185 186 187

    // Verify total number of posts in forum.
    $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="posts"]', $forum_arg);
    $this->assertFieldByXPath($xpath, '6', t('Number of posts found.'));
188 189

    // Test loading multiple forum nodes on the front page.
190
    $this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content', 'post comments')));
191 192 193 194
    $this->drupalPost('admin/structure/types/manage/forum', array('node_options[promote]' => 'promote'), t('Save content type'));
    $this->createForumTopic($this->forum, FALSE);
    $this->createForumTopic($this->forum, FALSE);
    $this->drupalGet('node');
195 196 197

    // Test adding a comment to a forum topic.
    $node = $this->createForumTopic($this->forum, FALSE);
198
    $edit = array();
199
    $edit['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = $this->randomName();
200
    $this->drupalPost("node/$node->nid", $edit, t('Save'));
201 202 203
    $this->assertResponse(200);

    // Test editing a forum topic that has a comment.
204
    $this->drupalLogin($this->edit_any_topics_user);
205
    $this->drupalGet('forum/' . $this->forum['tid']);
206 207
    $this->drupalPost("node/$node->nid/edit", array(), t('Save'));
    $this->assertResponse(200);
208 209
  }

210
  /**
211 212 213 214
   * Tests that forum nodes can't be added without a parent.
   *
   * Verifies that forum nodes are not created without choosing "forum" from the
   * select list.
215 216
   */
  function testAddOrphanTopic() {
217 218 219
    // Must remove forum topics to test creating orphan topics.
    $vid = variable_get('forum_nav_vocabulary');
    $tree = taxonomy_get_tree($vid);
220
    foreach ($tree as $term) {
221 222 223 224
      taxonomy_term_delete($term->tid);
    }

    // Create an orphan forum item.
225
    $this->drupalLogin($this->admin_user);
226
    $this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . LANGUAGE_NOT_SPECIFIED .'][0][value]' => $this->randomName(120)), t('Save'));
227 228

    $nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField();
229
    $this->assertEqual(0, $nid_count, t('A forum node was not created when missing a forum vocabulary.'));
230 231 232

    // Reset the defaults for future tests.
    module_enable(array('forum'));
233 234
  }

235
  /**
236
   * Runs admin tests on the admin user.
237
   *
238 239
   * @param object $user
   *   The logged-in user.
240 241 242 243 244 245 246
   */
  private function doAdminTests($user) {
    // Login the user.
    $this->drupalLogin($user);

    // Enable the active forum block.
    $edit = array();
247
    $edit['blocks[forum_active][region]'] = 'sidebar_second';
248
    $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
249
    $this->assertResponse(200);
250
    $this->assertText(t('The block settings have been updated.'), t('Active forum topics forum block was enabled'));
251 252 253

    // Enable the new forum block.
    $edit = array();
254
    $edit['blocks[forum_new][region]'] = 'sidebar_second';
255
    $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
256
    $this->assertResponse(200);
257
    $this->assertText(t('The block settings have been updated.'), t('[New forum topics] Forum block was enabled'));
258 259

    // Retrieve forum menu id.
260
    $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = 'forum' AND menu_name = 'navigation' AND module = 'system' ORDER BY mlid ASC", 0, 1)->fetchField();
261 262 263

    // Add forum to navigation menu.
    $edit = array();
264
    $this->drupalPost('admin/structure/menu/manage/navigation', $edit, t('Save configuration'));
265 266 267 268 269 270 271
    $this->assertResponse(200);

    // Edit forum taxonomy.
    // Restoration of the settings fails and causes subsequent tests to fail.
    $this->container = $this->editForumTaxonomy();
    // Create forum container.
    $this->container = $this->createForum('container');
272 273 274
    // Verify "edit container" link exists and functions correctly.
    $this->drupalGet('admin/structure/forum');
    $this->clickLink('edit container');
275
    $this->assertRaw('Edit container', t('Followed the link to edit the container'));
276 277
    // Create forum inside the forum container.
    $this->forum = $this->createForum('forum', $this->container['tid']);
278 279 280
    // Verify the "edit forum" link exists and functions correctly.
    $this->drupalGet('admin/structure/forum');
    $this->clickLink('edit forum');
281
    $this->assertRaw('Edit forum', t('Followed the link to edit the forum'));
282 283
    // Navigate back to forum structure page.
    $this->drupalGet('admin/structure/forum');
284 285
    // Create second forum in container.
    $this->delete_forum = $this->createForum('forum', $this->container['tid']);
286 287
    // Save forum overview.
    $this->drupalPost('admin/structure/forum/', array(), t('Save'));
288
    $this->assertRaw(t('The configuration options have been saved.'));
289
    // Delete this second forum.
290
    $this->deleteForum($this->delete_forum['tid']);
291 292
    // Create forum at the top (root) level.
    $this->root_forum = $this->createForum('forum');
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

    // Test vocabulary form alterations.
    $this->drupalGet('admin/structure/taxonomy/forums/edit');
    $this->assertFieldByName('op', t('Save'), 'Save button found.');
    $this->assertNoFieldByName('op', t('Delete'), 'Delete button not found.');

    // Test term edit form alterations.
    $this->drupalGet('taxonomy/term/' . $this->container['tid'] . '/edit');
    // Test parent field been hidden by forum module.
    $this->assertNoField('parent[]', 'Parent field not found.');

    // Create a default vocabulary named "Tags".
    $description = 'Use tags to group articles on similar topics into categories.';
    $help = 'Enter a comma-separated list of words to describe your content.';
    $vocabulary = entity_create('taxonomy_vocabulary', array(
      'name' => 'Tags',
      'description' => $description,
      'machine_name' => 'tags',
      'langcode' => language_default()->langcode,
      'help' => $help,
    ));
    taxonomy_vocabulary_save($vocabulary);
    // Test tags vocabulary form is not affected.
    $this->drupalGet('admin/structure/taxonomy/tags/edit');
    $this->assertFieldByName('op', t('Save'), 'Save button found.');
    $this->assertFieldByName('op', t('Delete'), 'Delete button found.');
    // Test tags vocabulary term form is not affected.
    $this->drupalGet('admin/structure/taxonomy/tags/add');
    $this->assertField('parent[]', 'Parent field found.');
    // Test relations fieldset exists.
    $relations_fieldset = $this->xpath("//fieldset[@id='edit-relations']");
    $this->assertTrue(isset($relations_fieldset[0]), 'Relations fieldset element found.');
325 326 327
  }

  /**
328
   * Edits the forum taxonomy.
329 330 331 332
   */
  function editForumTaxonomy() {
    // Backup forum taxonomy.
    $vid = variable_get('forum_nav_vocabulary', '');
333
    $original_settings = taxonomy_vocabulary_load($vid);
334 335 336 337 338 339 340 341

    // Generate a random name/description.
    $title = $this->randomName(10);
    $description = $this->randomName(100);

    $edit = array(
      'name' => $title,
      'description' => $description,
342
      'machine_name' => drupal_strtolower(drupal_substr($this->randomName(), 3, 9)),
343 344 345
    );

    // Edit the vocabulary.
346
    $this->drupalPost('admin/structure/taxonomy/' . $original_settings->machine_name . '/edit', $edit, t('Save'));
347
    $this->assertResponse(200);
348
    $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $title)), t('Vocabulary was edited'));
349 350

    // Grab the newly edited vocabulary.
351
    entity_get_controller('taxonomy_vocabulary')->resetCache();
352
    $current_settings = taxonomy_vocabulary_load($vid);
353 354

    // Make sure we actually edited the vocabulary properly.
355 356
    $this->assertEqual($current_settings->name, $title, t('The name was updated'));
    $this->assertEqual($current_settings->description, $description, t('The description was updated'));
357

358
    // Restore the original vocabulary.
359
    taxonomy_vocabulary_save($original_settings);
360 361
    drupal_static_reset('taxonomy_vocabulary_load');
    $current_settings = taxonomy_vocabulary_load($vid);
362
    $this->assertEqual($current_settings->name, $original_settings->name, 'The original vocabulary settings were restored');
363 364 365
  }

  /**
366
   * Creates a forum container or a forum.
367
   *
368
   * @param $type
369
   *   The forum type (forum container or forum).
370
   * @param $parent
371 372
   *   The forum parent. This defaults to 0, indicating a root forum.
   *
373
   * @return
374
   *   The created taxonomy term data.
375 376 377 378 379 380 381 382 383 384 385 386 387 388
   */
  function createForum($type, $parent = 0) {
    // Generate a random name/description.
    $name = $this->randomName(10);
    $description = $this->randomName(100);

    $edit = array(
      'name' => $name,
      'description' => $description,
      'parent[0]' => $parent,
      'weight' => '0',
    );

    // Create forum.
389
    $this->drupalPost('admin/structure/forum/add/' . $type, $edit, t('Save'));
390 391
    $this->assertResponse(200);
    $type = ($type == 'container') ? 'forum container' : 'forum';
392
    $this->assertRaw(t('Created new @type %term.', array('%term' => $name, '@type' => t($type))), t(ucfirst($type) . ' was created'));
393 394

    // Verify forum.
395
    $term = db_query("SELECT * FROM {taxonomy_term_data} t WHERE t.vid = :vid AND t.name = :name AND t.description = :desc", array(':vid' => variable_get('forum_nav_vocabulary', ''), ':name' => $name, ':desc' => $description))->fetchAssoc();
396
    $this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
397 398 399

    // Verify forum hierarchy.
    $tid = $term['tid'];
400
    $parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(':tid' => $tid))->fetchField();
401
    $this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
402 403 404 405

    return $term;
  }

406
  /**
407
   * Deletes a forum.
408
   *
409 410
   * @param $tid
   *   The forum ID.
411 412
   */
  function deleteForum($tid) {
413
    // Delete the forum.
414
    $this->drupalPost('admin/structure/forum/edit/forum/' . $tid, array(), t('Delete'));
415
    $this->drupalPost(NULL, array(), t('Delete'));
416

417
    // Assert that the forum no longer exists.
418
    $this->drupalGet('forum/' . $tid);
419
    $this->assertResponse(404, 'The forum was not found');
420 421 422 423 424

    // Assert that the associated term has been removed from the
    // forum_containers variable.
    $containers = variable_get('forum_containers', array());
    $this->assertFalse(in_array($tid, $containers), 'The forum_containers variable has been updated.');
425 426
  }

427
  /**
428
   * Runs basic tests on the indicated user.
429
   *
430 431 432 433
   * @param $user
   *   The logged in user.
   * @param $admin
   *   User has 'access administration pages' privilege.
434 435 436 437 438 439 440 441 442 443 444 445 446
   */
  private function doBasicTests($user, $admin) {
    // Login the user.
    $this->drupalLogin($user);
    // Attempt to create forum topic under a container.
    $this->createForumTopic($this->container, TRUE);
    // Create forum node.
    $node = $this->createForumTopic($this->forum, FALSE);
    // Verify the user has access to all the forum nodes.
    $this->verifyForums($user, $node, $admin);
  }

  /**
447
   * Creates a forum topic.
448
   *
449
   * @param array $forum
450
   *   A forum array.
451
   * @param boolean $container
452
   *   TRUE if $forum is a container; FALSE otherwise.
453 454
   *
   * @return object
455
   *   The created topic node.
456 457 458 459 460
   */
  function createForumTopic($forum, $container = FALSE) {
    // Generate a random subject/body.
    $title = $this->randomName(20);
    $body = $this->randomName(200);
461

462
    $langcode = LANGUAGE_NOT_SPECIFIED;
463
    $edit = array(
464
      "title" => $title,
465
      "body[$langcode][0][value]" => $body,
466
    );
467
    $tid = $forum['tid'];
468

469
    // Create the forum topic, preselecting the forum ID via a URL parameter.
470
    $this->drupalPost('node/add/forum/' . $tid, $edit, t('Save'));
471

472 473
    $type = t('Forum topic');
    if ($container) {
474 475
      $this->assertNoRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), t('Forum topic was not created'));
      $this->assertRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), t('Error message was shown'));
476 477 478
      return;
    }
    else {
479 480
      $this->assertRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), t('Forum topic was created'));
      $this->assertNoRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), t('No error message was shown'));
481 482
    }

483
    // Retrieve node object, ensure that the topic was created and in the proper forum.
484
    $node = $this->drupalGetNodeByTitle($title);
485
    $this->assertTrue($node != NULL, t('Node @title was loaded', array('@title' => $title)));
486
    $this->assertEqual($node->taxonomy_forums[LANGUAGE_NOT_SPECIFIED][0]['tid'], $tid, 'Saved forum topic was in the expected forum');
487 488

    // View forum topic.
489
    $this->drupalGet('node/' . $node->nid);
490 491
    $this->assertRaw($title, t('Subject was found'));
    $this->assertRaw($body, t('Body was found'));
492 493 494 495 496

    return $node;
  }

  /**
497
   * Verifies that the logged in user has access to a forum node.
498
   *
499 500
   * @param $node_user
   *   The user who creates the node.
501
   * @param Drupal\node\Node $node
502 503 504 505 506
   *   The node being checked.
   * @param $admin
   *   Boolean to indicate whether the user can 'access administration pages'.
   * @param $response
   *   The exptected HTTP response code.
507
   */
508
  private function verifyForums($node_user, Node $node, $admin, $response = 200) {
509 510 511 512 513 514
    $response2 = ($admin) ? 200 : 403;

    // View forum help node.
    $this->drupalGet('admin/help/forum');
    $this->assertResponse($response2);
    if ($response2 == 200) {
515 516
      $this->assertTitle(t('Forum | Drupal'), t('Forum help title was displayed'));
      $this->assertText(t('Forum'), t('Forum help node was displayed'));
517 518 519 520 521
    }

    // Verify the forum blocks were displayed.
    $this->drupalGet('');
    $this->assertResponse(200);
522
    $this->assertText(t('New forum topics'), t('[New forum topics] Forum block was displayed'));
523 524 525 526 527 528 529 530 531

    // View forum container page.
    $this->verifyForumView($this->container);
    // View forum page.
    $this->verifyForumView($this->forum, $this->container);
    // View root forum page.
    $this->verifyForumView($this->root_forum);

    // View forum node.
532
    $this->drupalGet('node/' . $node->nid);
533
    $this->assertResponse(200);
534
    $this->assertTitle($node->label() . ' | Drupal', t('Forum node was displayed'));
535 536 537 538 539 540
    $breadcrumb = array(
      l(t('Home'), NULL),
      l(t('Forums'), 'forum'),
      l($this->container['name'], 'forum/' . $this->container['tid']),
      l($this->forum['name'], 'forum/' . $this->forum['tid']),
    );
541
    $this->assertRaw(theme('breadcrumb', array('breadcrumb' => $breadcrumb)), t('Breadcrumbs were displayed'));
542 543

    // View forum edit node.
544
    $this->drupalGet('node/' . $node->nid . '/edit');
545 546
    $this->assertResponse($response);
    if ($response == 200) {
547
      $this->assertTitle('Edit Forum topic ' . $node->label() . ' | Drupal', t('Forum edit node was displayed'));
548 549 550 551 552
    }

    if ($response == 200) {
      // Edit forum node (including moving it to another forum).
      $edit = array();
553
      $langcode = LANGUAGE_NOT_SPECIFIED;
554
      $edit["title"] = 'node/' . $node->nid;
555
      $edit["body[$langcode][0][value]"] = $this->randomName(256);
556
      // Assume the topic is initially associated with $forum.
557
      $edit["taxonomy_forums[$langcode]"] = $this->root_forum['tid'];
558
      $edit['shadow'] = TRUE;
559
      $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
560
      $this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit["title"])), t('Forum node was edited'));
561 562

      // Verify topic was moved to a different forum.
563 564 565 566
      $forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array(
        ':nid' => $node->nid,
        ':vid' => $node->vid,
      ))->fetchField();
567 568 569
      $this->assertTrue($forum_tid == $this->root_forum['tid'], 'The forum topic is linked to a different forum');

      // Delete forum node.
570
      $this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
571
      $this->assertResponse($response);
572
      $this->assertRaw(t('Forum topic %title has been deleted.', array('%title' => $edit['title'])), t('Forum node was deleted'));
573 574 575 576
    }
  }

  /**
577
   * Verifies the display of a forum page.
578
   *
579
   * @param $forum
580 581 582
   *   A row from the taxonomy_term_data table in an array.
   * @param $parent
   *   (optional) An array representing the forum's parent.
583 584 585
   */
  private function verifyForumView($forum, $parent = NULL) {
    // View forum page.
586
    $this->drupalGet('forum/' . $forum['tid']);
587
    $this->assertResponse(200);
588
    $this->assertTitle($forum['name'] . ' | Drupal', t('Forum name was displayed'));
589 590 591 592 593

    $breadcrumb = array(
      l(t('Home'), NULL),
      l(t('Forums'), 'forum'),
    );
594
    if (isset($parent)) {
595
      $breadcrumb[] = l($parent['name'], 'forum/' . $parent['tid']);
596
    }
597

598
    $this->assertRaw(theme('breadcrumb', array('breadcrumb' => $breadcrumb)), t('Breadcrumbs were displayed'));
599 600 601
  }

  /**
602
   * Generates forum topics to test the display of an active forum block.
603
   *
604 605
   * @param array $forum
   *   The forum array (a row from taxonomy_term_data table).
606 607 608 609 610 611 612 613 614 615
   */
  private function generateForumTopics($forum) {
    $this->nids = array();
    for ($i = 0; $i < 5; $i++) {
      $node = $this->createForumTopic($this->forum, FALSE);
      $this->nids[] = $node->nid;
    }
  }

  /**
616
   * Views forum topics to test the display of an active forum block.
617
   *
618 619
   * @todo The logic here is completely incorrect, since the active forum topics
   *   block is determined by comments on the node, not by views.
620 621 622 623
   * @todo DIE
   *
   * @param $nids
   *   An array of forum node IDs.
624 625 626 627
   */
  private function viewForumTopics($nids) {
    for ($i = 0; $i < 2; $i++) {
      foreach ($nids as $nid) {
628 629 630
        $this->drupalGet('node/' . $nid);
        $this->drupalGet('node/' . $nid);
        $this->drupalGet('node/' . $nid);
631 632 633 634
      }
    }
  }
}