forum.test

  1. drupal
    1. 7 modules/forum/forum.test
    2. 8 core/modules/forum/forum.test

Tests for forum.module.

Classes

NameDescription
ForumIndexTestCaseTests the forum index listing.
ForumTestCase

File

modules/forum/forum.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for forum.module.
  5. */
  6. class ForumTestCase extends DrupalWebTestCase {
  7. protected $admin_user;
  8. protected $edit_own_topics_user;
  9. protected $edit_any_topics_user;
  10. protected $web_user;
  11. protected $container;
  12. protected $forum;
  13. protected $root_forum;
  14. protected $nids;
  15. public static function getInfo() {
  16. return array(
  17. 'name' => 'Forum functionality',
  18. 'description' => 'Create, view, edit, delete, and change forum entries and verify its consistency in the database.',
  19. 'group' => 'Forum',
  20. );
  21. }
  22. /**
  23. * Enable modules and create users with specific permissions.
  24. */
  25. function setUp() {
  26. parent::setUp('taxonomy', 'comment', 'forum');
  27. // Create users.
  28. $this->admin_user = $this->drupalCreateUser(array(
  29. 'access administration pages',
  30. 'administer modules',
  31. 'administer blocks',
  32. 'administer forums',
  33. 'administer menu',
  34. 'administer taxonomy',
  35. 'create forum content',
  36. ));
  37. $this->edit_any_topics_user = $this->drupalCreateUser(array(
  38. 'access administration pages',
  39. 'create forum content',
  40. 'edit any forum content',
  41. 'delete any forum content',
  42. ));
  43. $this->edit_own_topics_user = $this->drupalCreateUser(array(
  44. 'create forum content',
  45. 'edit own forum content',
  46. 'delete own forum content',
  47. ));
  48. $this->web_user = $this->drupalCreateUser(array());
  49. }
  50. /**
  51. * Tests disabling and re-enabling forum.
  52. */
  53. function testEnableForumField() {
  54. $this->drupalLogin($this->admin_user);
  55. // Disable the forum module.
  56. $edit = array();
  57. $edit['modules[Core][forum][enable]'] = FALSE;
  58. $this->drupalPost('admin/modules', $edit, t('Save configuration'));
  59. $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
  60. module_list(TRUE);
  61. $this->assertFalse(module_exists('forum'), t('Forum module is not enabled.'));
  62. // Attempt to re-enable the forum module and ensure it does not try to
  63. // recreate the taxonomy_forums field.
  64. $edit = array();
  65. $edit['modules[Core][forum][enable]'] = 'forum';
  66. $this->drupalPost('admin/modules', $edit, t('Save configuration'));
  67. $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
  68. module_list(TRUE);
  69. $this->assertTrue(module_exists('forum'), t('Forum module is enabled.'));
  70. }
  71. /**
  72. * Login users, create forum nodes, and test forum functionality through the admin and user interfaces.
  73. */
  74. function testForum() {
  75. //Check that the basic forum install creates a default forum topic
  76. $this->drupalGet("/forum");
  77. // Look for the "General discussion" default forum
  78. $this->assertText(t("General discussion"), "Found the default forum at the /forum listing");
  79. // Do the admin tests.
  80. $this->doAdminTests($this->admin_user);
  81. // Generate topics to populate the active forum block.
  82. $this->generateForumTopics($this->forum);
  83. // Login an unprivileged user to view the forum topics and generate an
  84. // active forum topics list.
  85. $this->drupalLogin($this->web_user);
  86. // Verify that this user is shown a message that they may not post content.
  87. $this->drupalGet('forum/' . $this->forum['tid']);
  88. $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.");
  89. $this->viewForumTopics($this->nids);
  90. // Log in, and do basic tests for a user with permission to edit any forum
  91. // content.
  92. $this->doBasicTests($this->edit_any_topics_user, TRUE);
  93. // Create a forum node authored by this user.
  94. $any_topics_user_node = $this->createForumTopic($this->forum, FALSE);
  95. // Log in, and do basic tests for a user with permission to edit only its
  96. // own forum content.
  97. $this->doBasicTests($this->edit_own_topics_user, FALSE);
  98. // Create a forum node authored by this user.
  99. $own_topics_user_node = $this->createForumTopic($this->forum, FALSE);
  100. // Verify that this user cannot edit forum content authored by another user.
  101. $this->verifyForums($this->edit_any_topics_user, $any_topics_user_node, FALSE, 403);
  102. // Verify that this user is shown a local task to add new forum content.
  103. $this->drupalGet('forum');
  104. $this->assertLink(t('Add new Forum topic'));
  105. $this->drupalGet('forum/' . $this->forum['tid']);
  106. $this->assertLink(t('Add new Forum topic'));
  107. // Login a user with permission to edit any forum content.
  108. $this->drupalLogin($this->edit_any_topics_user);
  109. // Verify that this user can edit forum content authored by another user.
  110. $this->verifyForums($this->edit_own_topics_user, $own_topics_user_node, TRUE);
  111. // Verify the topic and post counts on the forum page.
  112. $this->drupalGet('forum');
  113. // Verify row for testing forum.
  114. $forum_arg = array(':forum' => 'forum-list-' . $this->forum['tid']);
  115. // Topics cell contains number of topics and number of unread topics.
  116. $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="topics"]', $forum_arg);
  117. $topics = $this->xpath($xpath);
  118. $topics = trim($topics[0]);
  119. $this->assertEqual($topics, '6', t('Number of topics found.'));
  120. // Verify the number of unread topics.
  121. $unread_topics = _forum_topics_unread($this->forum['tid'], $this->edit_any_topics_user->uid);
  122. $unread_topics = format_plural($unread_topics, '1 new', '@count new');
  123. $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="topics"]//a', $forum_arg);
  124. $this->assertFieldByXPath($xpath, $unread_topics, t('Number of unread topics found.'));
  125. // Verify total number of posts in forum.
  126. $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="posts"]', $forum_arg);
  127. $this->assertFieldByXPath($xpath, '6', t('Number of posts found.'));
  128. // Test loading multiple forum nodes on the front page.
  129. $this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content')));
  130. $this->drupalPost('admin/structure/types/manage/forum', array('node_options[promote]' => 'promote'), t('Save content type'));
  131. $this->createForumTopic($this->forum, FALSE);
  132. $this->createForumTopic($this->forum, FALSE);
  133. $this->drupalGet('node');
  134. // Test adding a comment to a forum topic.
  135. $node = $this->createForumTopic($this->forum, FALSE);
  136. $edit = array();
  137. $edit['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName();
  138. $this->drupalPost("node/$node->nid", $edit, t('Save'));
  139. $this->assertResponse(200);
  140. // Test editing a forum topic that has a comment.
  141. $this->drupalLogin($this->edit_any_topics_user);
  142. $this->drupalGet('forum/' . $this->forum['tid']);
  143. $this->drupalPost("node/$node->nid/edit", array(), t('Save'));
  144. $this->assertResponse(200);
  145. }
  146. /**
  147. * Forum nodes should not be created without choosing forum from select list.
  148. */
  149. function testAddOrphanTopic() {
  150. // Must remove forum topics to test creating orphan topics.
  151. $vid = variable_get('forum_nav_vocabulary');
  152. $tree = taxonomy_get_tree($vid);
  153. foreach ($tree as $term) {
  154. taxonomy_term_delete($term->tid);
  155. }
  156. // Create an orphan forum item.
  157. $this->drupalLogin($this->admin_user);
  158. $this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . LANGUAGE_NONE .'][0][value]' => $this->randomName(120)), t('Save'));
  159. $nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField();
  160. $this->assertEqual(0, $nid_count, t('A forum node was not created when missing a forum vocabulary.'));
  161. // Reset the defaults for future tests.
  162. module_enable(array('forum'));
  163. }
  164. /**
  165. * Run admin tests on the admin user.
  166. *
  167. * @param object $user The logged in user.
  168. */
  169. private function doAdminTests($user) {
  170. // Login the user.
  171. $this->drupalLogin($user);
  172. // Enable the active forum block.
  173. $edit = array();
  174. $edit['blocks[forum_active][region]'] = 'sidebar_second';
  175. $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  176. $this->assertResponse(200);
  177. $this->assertText(t('The block settings have been updated.'), t('Active forum topics forum block was enabled'));
  178. // Enable the new forum block.
  179. $edit = array();
  180. $edit['blocks[forum_new][region]'] = 'sidebar_second';
  181. $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  182. $this->assertResponse(200);
  183. $this->assertText(t('The block settings have been updated.'), t('[New forum topics] Forum block was enabled'));
  184. // Retrieve forum menu id.
  185. $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();
  186. // Add forum to navigation menu.
  187. $edit = array();
  188. $this->drupalPost('admin/structure/menu/manage/navigation', $edit, t('Save configuration'));
  189. $this->assertResponse(200);
  190. // Edit forum taxonomy.
  191. // Restoration of the settings fails and causes subsequent tests to fail.
  192. $this->container = $this->editForumTaxonomy();
  193. // Create forum container.
  194. $this->container = $this->createForum('container');
  195. // Verify "edit container" link exists and functions correctly.
  196. $this->drupalGet('admin/structure/forum');
  197. $this->clickLink('edit container');
  198. $this->assertRaw('Edit container', t('Followed the link to edit the container'));
  199. // Create forum inside the forum container.
  200. $this->forum = $this->createForum('forum', $this->container['tid']);
  201. // Verify the "edit forum" link exists and functions correctly.
  202. $this->drupalGet('admin/structure/forum');
  203. $this->clickLink('edit forum');
  204. $this->assertRaw('Edit forum', t('Followed the link to edit the forum'));
  205. // Navigate back to forum structure page.
  206. $this->drupalGet('admin/structure/forum');
  207. // Create second forum in container.
  208. $this->delete_forum = $this->createForum('forum', $this->container['tid']);
  209. // Save forum overview.
  210. $this->drupalPost('admin/structure/forum/', array(), t('Save'));
  211. $this->assertRaw(t('The configuration options have been saved.'));
  212. // Delete this second forum.
  213. $this->deleteForum($this->delete_forum['tid']);
  214. // Create forum at the top (root) level.
  215. $this->root_forum = $this->createForum('forum');
  216. // Test vocabulary form alterations.
  217. $this->drupalGet('admin/structure/taxonomy/forums/edit');
  218. $this->assertFieldByName('op', t('Save'), 'Save button found.');
  219. $this->assertNoFieldByName('op', t('Delete'), 'Delete button not found.');
  220. // Test term edit form alterations.
  221. $this->drupalGet('taxonomy/term/' . $this->container['tid'] . '/edit');
  222. // Test parent field been hidden by forum module.
  223. $this->assertNoField('parent[]', 'Parent field not found.');
  224. // Test tags vocabulary form is not affected.
  225. $this->drupalGet('admin/structure/taxonomy/tags/edit');
  226. $this->assertFieldByName('op', t('Save'), 'Save button found.');
  227. $this->assertFieldByName('op', t('Delete'), 'Delete button found.');
  228. // Test tags vocabulary term form is not affected.
  229. $this->drupalGet('admin/structure/taxonomy/tags/add');
  230. $this->assertField('parent[]', 'Parent field found.');
  231. // Test relations fieldset exists.
  232. $relations_fieldset = $this->xpath("//fieldset[@id='edit-relations']");
  233. $this->assertTrue(isset($relations_fieldset[0]), 'Relations fieldset element found.');
  234. }
  235. /**
  236. * Edit the forum taxonomy.
  237. */
  238. function editForumTaxonomy() {
  239. // Backup forum taxonomy.
  240. $vid = variable_get('forum_nav_vocabulary', '');
  241. $original_settings = taxonomy_vocabulary_load($vid);
  242. // Generate a random name/description.
  243. $title = $this->randomName(10);
  244. $description = $this->randomName(100);
  245. $edit = array(
  246. 'name' => $title,
  247. 'description' => $description,
  248. 'machine_name' => drupal_strtolower(drupal_substr($this->randomName(), 3, 9)),
  249. );
  250. // Edit the vocabulary.
  251. $this->drupalPost('admin/structure/taxonomy/' . $original_settings->machine_name . '/edit', $edit, t('Save'));
  252. $this->assertResponse(200);
  253. $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $title)), t('Vocabulary was edited'));
  254. // Grab the newly edited vocabulary.
  255. entity_get_controller('taxonomy_vocabulary')->resetCache();
  256. $current_settings = taxonomy_vocabulary_load($vid);
  257. // Make sure we actually edited the vocabulary properly.
  258. $this->assertEqual($current_settings->name, $title, t('The name was updated'));
  259. $this->assertEqual($current_settings->description, $description, t('The description was updated'));
  260. // Restore the original vocabulary.
  261. taxonomy_vocabulary_save($original_settings);
  262. drupal_static_reset('taxonomy_vocabulary_load');
  263. $current_settings = taxonomy_vocabulary_load($vid);
  264. $this->assertEqual($current_settings->name, $original_settings->name, 'The original vocabulary settings were restored');
  265. }
  266. /**
  267. * Create a forum container or a forum.
  268. *
  269. * @param $type
  270. * Forum type (forum container or forum).
  271. * @param $parent
  272. * Forum parent (default = 0 = a root forum; >0 = a forum container or
  273. * another forum).
  274. * @return
  275. * taxonomy_term_data created.
  276. */
  277. function createForum($type, $parent = 0) {
  278. // Generate a random name/description.
  279. $name = $this->randomName(10);
  280. $description = $this->randomName(100);
  281. $edit = array(
  282. 'name' => $name,
  283. 'description' => $description,
  284. 'parent[0]' => $parent,
  285. 'weight' => '0',
  286. );
  287. // Create forum.
  288. $this->drupalPost('admin/structure/forum/add/' . $type, $edit, t('Save'));
  289. $this->assertResponse(200);
  290. $type = ($type == 'container') ? 'forum container' : 'forum';
  291. $this->assertRaw(t('Created new @type %term.', array('%term' => $name, '@type' => t($type))), t(ucfirst($type) . ' was created'));
  292. // Verify forum.
  293. $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();
  294. $this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
  295. // Verify forum hierarchy.
  296. $tid = $term['tid'];
  297. $parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(':tid' => $tid))->fetchField();
  298. $this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
  299. return $term;
  300. }
  301. /**
  302. * Delete a forum.
  303. *
  304. * @param $tid
  305. * The forum ID.
  306. */
  307. function deleteForum($tid) {
  308. // Delete the forum.
  309. $this->drupalPost('admin/structure/forum/edit/forum/' . $tid, array(), t('Delete'));
  310. $this->drupalPost(NULL, array(), t('Delete'));
  311. // Assert that the forum no longer exists.
  312. $this->drupalGet('forum/' . $tid);
  313. $this->assertResponse(404, 'The forum was not found');
  314. // Assert that the associated term has been removed from the
  315. // forum_containers variable.
  316. $containers = variable_get('forum_containers', array());
  317. $this->assertFalse(in_array($tid, $containers), 'The forum_containers variable has been updated.');
  318. }
  319. /**
  320. * Run basic tests on the indicated user.
  321. *
  322. * @param $user
  323. * The logged in user.
  324. * @param $admin
  325. * User has 'access administration pages' privilege.
  326. */
  327. private function doBasicTests($user, $admin) {
  328. // Login the user.
  329. $this->drupalLogin($user);
  330. // Attempt to create forum topic under a container.
  331. $this->createForumTopic($this->container, TRUE);
  332. // Create forum node.
  333. $node = $this->createForumTopic($this->forum, FALSE);
  334. // Verify the user has access to all the forum nodes.
  335. $this->verifyForums($user, $node, $admin);
  336. }
  337. /**
  338. * Create forum topic.
  339. *
  340. * @param array $forum
  341. * Forum array.
  342. * @param boolean $container
  343. * True if $forum is a container.
  344. *
  345. * @return object
  346. * Topic node created.
  347. */
  348. function createForumTopic($forum, $container = FALSE) {
  349. // Generate a random subject/body.
  350. $title = $this->randomName(20);
  351. $body = $this->randomName(200);
  352. $langcode = LANGUAGE_NONE;
  353. $edit = array(
  354. "title" => $title,
  355. "body[$langcode][0][value]" => $body,
  356. );
  357. $tid = $forum['tid'];
  358. // Create the forum topic, preselecting the forum ID via a URL parameter.
  359. $this->drupalPost('node/add/forum/' . $tid, $edit, t('Save'));
  360. $type = t('Forum topic');
  361. if ($container) {
  362. $this->assertNoRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), t('Forum topic was not created'));
  363. $this->assertRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), t('Error message was shown'));
  364. return;
  365. }
  366. else {
  367. $this->assertRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), t('Forum topic was created'));
  368. $this->assertNoRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), t('No error message was shown'));
  369. }
  370. // Retrieve node object, ensure that the topic was created and in the proper forum.
  371. $node = $this->drupalGetNodeByTitle($title);
  372. $this->assertTrue($node != NULL, t('Node @title was loaded', array('@title' => $title)));
  373. $this->assertEqual($node->taxonomy_forums[LANGUAGE_NONE][0]['tid'], $tid, 'Saved forum topic was in the expected forum');
  374. // View forum topic.
  375. $this->drupalGet('node/' . $node->nid);
  376. $this->assertRaw($title, t('Subject was found'));
  377. $this->assertRaw($body, t('Body was found'));
  378. return $node;
  379. }
  380. /**
  381. * Verify the logged in user has access to a forum nodes.
  382. *
  383. * @param $node_user
  384. * The user who creates the node.
  385. * @param $node
  386. * The node being checked.
  387. * @param $admin
  388. * Boolean to indicate whether the user can 'access administration pages'.
  389. * @param $response
  390. * The exptected HTTP response code.
  391. */
  392. private function verifyForums($node_user, $node, $admin, $response = 200) {
  393. $response2 = ($admin) ? 200 : 403;
  394. // View forum help node.
  395. $this->drupalGet('admin/help/forum');
  396. $this->assertResponse($response2);
  397. if ($response2 == 200) {
  398. $this->assertTitle(t('Forum | Drupal'), t('Forum help title was displayed'));
  399. $this->assertText(t('Forum'), t('Forum help node was displayed'));
  400. }
  401. // Verify the forum blocks were displayed.
  402. $this->drupalGet('');
  403. $this->assertResponse(200);
  404. $this->assertText(t('New forum topics'), t('[New forum topics] Forum block was displayed'));
  405. // View forum container page.
  406. $this->verifyForumView($this->container);
  407. // View forum page.
  408. $this->verifyForumView($this->forum, $this->container);
  409. // View root forum page.
  410. $this->verifyForumView($this->root_forum);
  411. // View forum node.
  412. $this->drupalGet('node/' . $node->nid);
  413. $this->assertResponse(200);
  414. $this->assertTitle($node->title . ' | Drupal', t('Forum node was displayed'));
  415. $breadcrumb = array(
  416. l(t('Home'), NULL),
  417. l(t('Forums'), 'forum'),
  418. l($this->container['name'], 'forum/' . $this->container['tid']),
  419. l($this->forum['name'], 'forum/' . $this->forum['tid']),
  420. );
  421. $this->assertRaw(theme('breadcrumb', array('breadcrumb' => $breadcrumb)), t('Breadcrumbs were displayed'));
  422. // View forum edit node.
  423. $this->drupalGet('node/' . $node->nid . '/edit');
  424. $this->assertResponse($response);
  425. if ($response == 200) {
  426. $this->assertTitle('Edit Forum topic ' . $node->title . ' | Drupal', t('Forum edit node was displayed'));
  427. }
  428. if ($response == 200) {
  429. // Edit forum node (including moving it to another forum).
  430. $edit = array();
  431. $langcode = LANGUAGE_NONE;
  432. $edit["title"] = 'node/' . $node->nid;
  433. $edit["body[$langcode][0][value]"] = $this->randomName(256);
  434. // Assume the topic is initially associated with $forum.
  435. $edit["taxonomy_forums[$langcode]"] = $this->root_forum['tid'];
  436. $edit['shadow'] = TRUE;
  437. $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
  438. $this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit["title"])), t('Forum node was edited'));
  439. // Verify topic was moved to a different forum.
  440. $forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array(
  441. ':nid' => $node->nid,
  442. ':vid' => $node->vid,
  443. ))->fetchField();
  444. $this->assertTrue($forum_tid == $this->root_forum['tid'], 'The forum topic is linked to a different forum');
  445. // Delete forum node.
  446. $this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
  447. $this->assertResponse($response);
  448. $this->assertRaw(t('Forum topic %title has been deleted.', array('%title' => $edit['title'])), t('Forum node was deleted'));
  449. }
  450. }
  451. /**
  452. * Verify display of forum page.
  453. *
  454. * @param $forum
  455. * A row from taxonomy_term_data table in array.
  456. */
  457. private function verifyForumView($forum, $parent = NULL) {
  458. // View forum page.
  459. $this->drupalGet('forum/' . $forum['tid']);
  460. $this->assertResponse(200);
  461. $this->assertTitle($forum['name'] . ' | Drupal', t('Forum name was displayed'));
  462. $breadcrumb = array(
  463. l(t('Home'), NULL),
  464. l(t('Forums'), 'forum'),
  465. );
  466. if (isset($parent)) {
  467. $breadcrumb[] = l($parent['name'], 'forum/' . $parent['tid']);
  468. }
  469. $this->assertRaw(theme('breadcrumb', array('breadcrumb' => $breadcrumb)), t('Breadcrumbs were displayed'));
  470. }
  471. /**
  472. * Generate forum topics to test display of active forum block.
  473. *
  474. * @param array $forum Forum array (a row from taxonomy_term_data table).
  475. */
  476. private function generateForumTopics($forum) {
  477. $this->nids = array();
  478. for ($i = 0; $i < 5; $i++) {
  479. $node = $this->createForumTopic($this->forum, FALSE);
  480. $this->nids[] = $node->nid;
  481. }
  482. }
  483. /**
  484. * View forum topics to test display of active forum block.
  485. *
  486. * @todo The logic here is completely incorrect, since the active
  487. * forum topics block is determined by comments on the node, not by views.
  488. * @todo DIE
  489. *
  490. * @param $nids
  491. * An array of forum node IDs.
  492. */
  493. private function viewForumTopics($nids) {
  494. for ($i = 0; $i < 2; $i++) {
  495. foreach ($nids as $nid) {
  496. $this->drupalGet('node/' . $nid);
  497. $this->drupalGet('node/' . $nid);
  498. $this->drupalGet('node/' . $nid);
  499. }
  500. }
  501. }
  502. }
  503. /**
  504. * Tests the forum index listing.
  505. */
  506. class ForumIndexTestCase extends DrupalWebTestCase {
  507. public static function getInfo() {
  508. return array(
  509. 'name' => 'Forum index',
  510. 'description' => 'Tests the forum index listing.',
  511. 'group' => 'Forum',
  512. );
  513. }
  514. function setUp() {
  515. parent::setUp('taxonomy', 'comment', 'forum');
  516. // Create a test user.
  517. $web_user = $this->drupalCreateUser(array('create forum content', 'edit own forum content', 'edit any forum content', 'administer nodes'));
  518. $this->drupalLogin($web_user);
  519. }
  520. /**
  521. * Tests the forum index for published and unpublished nodes.
  522. */
  523. function testForumIndexStatus() {
  524. $langcode = LANGUAGE_NONE;
  525. // The forum ID to use.
  526. $tid = 1;
  527. // Create a test node.
  528. $title = $this->randomName(20);
  529. $edit = array(
  530. "title" => $title,
  531. "body[$langcode][0][value]" => $this->randomName(200),
  532. );
  533. // Create the forum topic, preselecting the forum ID via a URL parameter.
  534. $this->drupalPost('node/add/forum/' . $tid, $edit, t('Save'));
  535. // Check that the node exists in the database.
  536. $node = $this->drupalGetNodeByTitle($title);
  537. $this->assertTrue(!empty($node), 'New forum node found in database.');
  538. // Verify that the node appears on the index.
  539. $this->drupalGet('forum/' . $tid);
  540. $this->assertText($title, 'Published forum topic appears on index.');
  541. // Unpublish the node.
  542. $edit = array(
  543. 'status' => FALSE,
  544. );
  545. $this->drupalPost("node/{$node->nid}/edit", $edit, t('Save'));
  546. $this->assertText(t('Access denied'), 'Unpublished node is no longer accessible.');
  547. // Verify that the node no longer appears on the index.
  548. $this->drupalGet('forum/' . $tid);
  549. $this->assertNoText($title, 'Unpublished forum topic no longer appears on index.');
  550. }
  551. }
Login or register to post comments