Newer
Older
<?php
Alex Pott
committed
namespace Drupal\Tests\forum\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
Angie Byron
committed
use Drupal\Core\Entity\EntityInterface;
Angie Byron
committed
use Drupal\Core\Link;
use Drupal\Core\Url;
Alex Pott
committed
use Drupal\taxonomy\Entity\Vocabulary;
Alex Pott
committed
use Drupal\Tests\BrowserTestBase;
Jennifer Hodgdon
committed
/**
* Tests for forum.module.
*
* Create, view, edit, delete, and change forum entries and verify its
* consistency in the database.
*
* @group forum
Jennifer Hodgdon
committed
*/
Alex Pott
committed
class ForumTest extends BrowserTestBase {
Jennifer Hodgdon
committed
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'comment', 'forum', 'node', 'block', 'menu_ui', 'help'];
Jennifer Hodgdon
committed
/**
* A user with various administrative privileges.
*/
Alex Pott
committed
protected $adminUser;
Jennifer Hodgdon
committed
/**
* A user that can create forum topics and edit its own topics.
*/
Alex Pott
committed
protected $editOwnTopicsUser;
Jennifer Hodgdon
committed
/**
* A user that can create, edit, and delete forum topics.
*/
Alex Pott
committed
protected $editAnyTopicsUser;
Jennifer Hodgdon
committed
/**
* A user with no special privileges.
*/
Alex Pott
committed
protected $webUser;
/**
* An administrative user who can bypass comment approval.
*/
protected $postCommentUser;
Jennifer Hodgdon
committed
/**
* An array representing a forum container.
Jennifer Hodgdon
committed
*/
protected $forumContainer;
Jennifer Hodgdon
committed
/**
* An array representing a forum.
*/
protected $forum;
Jennifer Hodgdon
committed
/**
* An array representing a root forum.
*/
Alex Pott
committed
protected $rootForum;
Jennifer Hodgdon
committed
/**
* An array of forum topic node IDs.
*/
protected $nids;
/**
* {@inheritdoc}
*/
Alex Pott
committed
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
$this->drupalPlaceBlock('page_title_block');
// Create users.
$this->adminUser = $this->drupalCreateUser([
Dries Buytaert
committed
'access administration pages',
Angie Byron
committed
'administer modules',
Dries Buytaert
committed
'administer blocks',
'administer forums',
'administer menu',
'administer taxonomy',
'create forum content',
'access comments',
]);
$this->editAnyTopicsUser = $this->drupalCreateUser([
Dries Buytaert
committed
'access administration pages',
'create forum content',
'edit any forum content',
'delete any forum content',
]);
$this->editOwnTopicsUser = $this->drupalCreateUser([
Dries Buytaert
committed
'create forum content',
'edit own forum content',
'delete own forum content',
]);
Alex Pott
committed
$this->webUser = $this->drupalCreateUser();
$this->postCommentUser = $this->drupalCreateUser([
'administer content types',
'create forum content',
'post comments',
'skip comment approval',
'access comments',
]);
$this->drupalPlaceBlock('help_block', ['region' => 'help']);
$this->drupalPlaceBlock('local_actions_block');
}
/**
Jennifer Hodgdon
committed
* Tests forum functionality through the admin and user interfaces.
*/
function testForum() {
Dries Buytaert
committed
//Check that the basic forum install creates a default forum topic
$this->drupalGet('/forum');
Dries Buytaert
committed
// Look for the "General discussion" default forum
$this->assertRaw(Link::createFromRoute(t('General discussion'), 'forum.page', ['taxonomy_term' => 1])->toString(), "Found the default forum at the /forum listing");
// Check the presence of expected cache tags.
$this->assertCacheTag('config:forum.settings');
$this->drupalGet(Url::fromRoute('forum.page', ['taxonomy_term' => 1]));
$this->assertCacheTag('config:forum.settings');
// Do the admin tests.
Alex Pott
committed
$this->doAdminTests($this->adminUser);
// Check display order.
$display = EntityViewDisplay::load('node.forum.default');
$body = $display->getComponent('body');
$comment = $display->getComponent('comment_forum');
$taxonomy = $display->getComponent('taxonomy_forums');
// Assert field order is body » taxonomy » comments.
$this->assertTrue($taxonomy['weight'] < $body['weight']);
$this->assertTrue($body['weight'] < $comment['weight']);
// Check form order.
$display = EntityFormDisplay::load('node.forum.default');
$body = $display->getComponent('body');
$comment = $display->getComponent('comment_forum');
$taxonomy = $display->getComponent('taxonomy_forums');
// Assert category comes before body in order.
$this->assertTrue($taxonomy['weight'] < $body['weight']);
Angie Byron
committed
$this->generateForumTopics();
// Log in an unprivileged user to view the forum topics and generate an
// active forum topics list.
Alex Pott
committed
$this->drupalLogin($this->webUser);
Angie Byron
committed
// Verify that this user is shown a message that they may not post content.
$this->drupalGet('forum/' . $this->forum['tid']);
Alex Pott
committed
$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.");
// Log in, and do basic tests for a user with permission to edit any forum
// content.
Alex Pott
committed
$this->doBasicTests($this->editAnyTopicsUser, 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.
Alex Pott
committed
$this->doBasicTests($this->editOwnTopicsUser, 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.
Angie Byron
committed
$this->verifyForums($any_topics_user_node, FALSE, 403);
Angie Byron
committed
// 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'));
// Log in a user with permission to edit any forum content.
Alex Pott
committed
$this->drupalLogin($this->editAnyTopicsUser);
// Verify that this user can edit forum content authored by another user.
Angie Byron
committed
$this->verifyForums($own_topics_user_node, TRUE);
// Verify the topic and post counts on the forum page.
$this->drupalGet('forum');
Angie Byron
committed
// Verify row for testing forum.
$forum_arg = [':forum' => 'forum-list-' . $this->forum['tid']];
Angie Byron
committed
// Topics cell contains number of topics and number of unread topics.
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="forum__topics"]', $forum_arg);
Angie Byron
committed
$topics = $this->xpath($xpath);
Alex Pott
committed
$topics = trim($topics[0]->getText());
// The extracted text contains the number of topics (6) and new posts
// (also 6) in this table cell.
$this->assertEquals('6 6 new posts in forum ' . $this->forum['name'], $topics, 'Number of topics found.');
Angie Byron
committed
// Verify the number of unread topics.
Alex Pott
committed
$elements = $this->xpath('//tr[@id=:forum]//td[@class="forum__topics"]//a', $forum_arg);
$this->assertStringStartsWith('6 new posts', $elements[0]->getText(), 'Number of unread topics found.');
// Verify that the forum name is in the unread topics text.
Alex Pott
committed
$elements = $this->xpath('//tr[@id=:forum]//em[@class="placeholder"]', $forum_arg);
$this->assertContains($this->forum['name'], $elements[0]->getText(), 'Forum name found in unread topics text.');
Angie Byron
committed
// Verify total number of posts in forum.
Alex Pott
committed
$elements = $this->xpath('//tr[@id=:forum]//td[@class="forum__posts"]', $forum_arg);
$this->assertEquals('6', $elements[0]->getText(), 'Number of posts found.');
// Test loading multiple forum nodes on the front page.
$this->drupalLogin($this->drupalCreateUser(['administer content types', 'create forum content', 'post comments']));
$this->drupalPostForm('admin/structure/types/manage/forum', ['options[promote]' => 'promote'], t('Save content type'));
$this->createForumTopic($this->forum, FALSE);
$this->createForumTopic($this->forum, FALSE);
$this->drupalGet('node');
// Test adding a comment to a forum topic.
$node = $this->createForumTopic($this->forum, FALSE);
$edit = [];
Alex Pott
committed
$edit['comment_body[0][value]'] = $this->randomMachineName();
$this->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
$this->assertResponse(200);
// Test editing a forum topic that has a comment.
Alex Pott
committed
$this->drupalLogin($this->editAnyTopicsUser);
$this->drupalGet('forum/' . $this->forum['tid']);
$this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save'));
$this->assertResponse(200);
// Test the root forum page title change.
$this->drupalGet('forum');
catch
committed
$this->assertCacheTag('config:taxonomy.vocabulary.' . $this->forum['vid']);
$this->assertTitle(t('Forums | Drupal'));
Alex Pott
committed
$vocabulary = Vocabulary::load($this->forum['vid']);
$vocabulary->set('name', 'Discussions');
$vocabulary->save();
$this->drupalGet('forum');
$this->assertTitle(t('Discussions | Drupal'));
// Test anonymous action link.
$this->drupalLogout();
$this->drupalGet('forum/' . $this->forum['tid']);
$this->assertLink(t('Log in to post new content in the forum.'));
}
Angie Byron
committed
/**
Jennifer Hodgdon
committed
* 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.
Angie Byron
committed
*/
function testAddOrphanTopic() {
Dries Buytaert
committed
// Must remove forum topics to test creating orphan topics.
$vid = $this->config('forum.settings')->get('vocabulary');
$tids = \Drupal::entityQuery('taxonomy_term')
->condition('vid', $vid)
->execute();
Alex Pott
committed
entity_delete_multiple('taxonomy_term', $tids);
Dries Buytaert
committed
// Create an orphan forum item.
$edit = [];
Alex Pott
committed
$edit['title[0][value]'] = $this->randomMachineName(10);
$edit['body[0][value]'] = $this->randomMachineName(120);
Alex Pott
committed
$this->drupalLogin($this->adminUser);
$this->drupalPostForm('node/add/forum', $edit, t('Save'));
Angie Byron
committed
$nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField();
Dries Buytaert
committed
$this->assertEqual(0, $nid_count, 'A forum node was not created when missing a forum vocabulary.');
Dries Buytaert
committed
// Reset the defaults for future tests.
\Drupal::service('module_installer')->install(['forum']);
Angie Byron
committed
}
/**
Jennifer Hodgdon
committed
* Runs admin tests on the admin user.
*
Jennifer Hodgdon
committed
* @param object $user
* The logged-in user.
*/
private function doAdminTests($user) {
// Log in the user.
$this->drupalLogin($user);
Dries Buytaert
committed
// Add forum to the Tools menu.
$edit = [];
$this->drupalPostForm('admin/structure/menu/manage/tools', $edit, t('Save'));
$this->assertResponse(200);
// Edit forum taxonomy.
// Restoration of the settings fails and causes subsequent tests to fail.
$this->editForumVocabulary();
// Create forum container.
$this->forumContainer = $this->createForum('container');
Dries Buytaert
committed
// Verify "edit container" link exists and functions correctly.
$this->drupalGet('admin/structure/forum');
Angie Byron
committed
// Verify help text is shown.
$this->assertText(t('Forums contain forum topics. Use containers to group related forums'));
// Verify action links are there.
$this->assertLink('Add forum');
$this->assertLink('Add container');
Dries Buytaert
committed
$this->clickLink('edit container');
Dries Buytaert
committed
$this->assertRaw('Edit container', 'Followed the link to edit the container');
// Create forum inside the forum container.
$this->forum = $this->createForum('forum', $this->forumContainer['tid']);
Dries Buytaert
committed
// Verify the "edit forum" link exists and functions correctly.
$this->drupalGet('admin/structure/forum');
$this->clickLink('edit forum');
Dries Buytaert
committed
$this->assertRaw('Edit forum', 'Followed the link to edit the forum');
Dries Buytaert
committed
// Navigate back to forum structure page.
$this->drupalGet('admin/structure/forum');
Alex Pott
committed
// Create second forum in container, destined to be deleted below.
$delete_forum = $this->createForum('forum', $this->forumContainer['tid']);
// Save forum overview.
$this->drupalPostForm('admin/structure/forum/', [], t('Save'));
$this->assertRaw(t('The configuration options have been saved.'));
// Delete this second forum.
Alex Pott
committed
$this->deleteForum($delete_forum['tid']);
// Create forum at the top (root) level.
Alex Pott
committed
$this->rootForum = $this->createForum('forum');
// Test vocabulary form alterations.
Alex Pott
committed
$this->drupalGet('admin/structure/taxonomy/manage/forums');
Alex Pott
committed
$this->assertSession()->buttonExists('Save');
$this->assertSession()->buttonNotExists('Delete');
// Test term edit form alterations.
$this->drupalGet('taxonomy/term/' . $this->forumContainer['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 = Vocabulary::create([
'name' => 'Tags',
'description' => $description,
'vid' => 'tags',
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
'help' => $help,
Alex Pott
committed
$vocabulary->save();
// Test tags vocabulary form is not affected.
Alex Pott
committed
$this->drupalGet('admin/structure/taxonomy/manage/tags');
Alex Pott
committed
$this->assertSession()->buttonExists('Save');
$this->assertLink(t('Delete'));
// Test tags vocabulary term form is not affected.
$this->drupalGet('admin/structure/taxonomy/manage/tags/add');
$this->assertField('parent[]', 'Parent field found.');
// Test relations widget exists.
$relations_widget = $this->xpath("//details[@id='edit-relations']");
$this->assertTrue(isset($relations_widget[0]), 'Relations widget element found.');
}
/**
Jennifer Hodgdon
committed
* Edits the forum taxonomy.
*/
function editForumVocabulary() {
// Backup forum taxonomy.
$vid = $this->config('forum.settings')->get('vocabulary');
Alex Pott
committed
$original_vocabulary = Vocabulary::load($vid);
// Generate a random name and description.
$edit = [
Alex Pott
committed
'name' => $this->randomMachineName(10),
'description' => $this->randomMachineName(100),
];
// Edit the vocabulary.
Alex Pott
committed
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $original_vocabulary->id(), $edit, t('Save'));
$this->assertResponse(200);
$this->assertRaw(t('Updated vocabulary %name.', ['%name' => $edit['name']]), 'Vocabulary was edited');
// Grab the newly edited vocabulary.
Alex Pott
committed
$current_vocabulary = Vocabulary::load($vid);
// Make sure we actually edited the vocabulary properly.
$this->assertEqual($current_vocabulary->label(), $edit['name'], 'The name was updated');
$this->assertEqual($current_vocabulary->getDescription(), $edit['description'], 'The description was updated');
// Restore the original vocabulary's name and description.
$current_vocabulary->set('name', $original_vocabulary->label());
$current_vocabulary->set('description', $original_vocabulary->getDescription());
$current_vocabulary->save();
// Reload vocabulary to make sure changes are saved.
Alex Pott
committed
$current_vocabulary = Vocabulary::load($vid);
$this->assertEqual($current_vocabulary->label(), $original_vocabulary->label(), 'The original vocabulary settings were restored');
}
/**
Jennifer Hodgdon
committed
* Creates a forum container or a forum.
*
* @param string $type
Jennifer Hodgdon
committed
* The forum type (forum container or forum).
* @param int $parent
Jennifer Hodgdon
committed
* The forum parent. This defaults to 0, indicating a root forum.
*
* @return \Drupal\Core\Database\StatementInterface
Jennifer Hodgdon
committed
* The created taxonomy term data.
*/
function createForum($type, $parent = 0) {
// Generate a random name/description.
Alex Pott
committed
$name = $this->randomMachineName(10);
$description = $this->randomMachineName(100);
$edit = [
'name[0][value]' => $name,
'description[0][value]' => $description,
'parent[0]' => $parent,
'weight' => '0',
];
// Create forum.
$this->drupalPostForm('admin/structure/forum/add/' . $type, $edit, t('Save'));
$this->assertResponse(200);
$type = ($type == 'container') ? 'forum container' : 'forum';
$this->assertText(
Dries Buytaert
committed
t(
'Created new @type @term.',
['@term' => $name, '@type' => t($type)]
Dries Buytaert
committed
),
format_string('@type was created', ['@type' => ucfirst($type)])
Dries Buytaert
committed
);
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
// Verify forum.
$term = db_query("SELECT * FROM {taxonomy_term_field_data} t WHERE t.vid = :vid AND t.name = :name AND t.description__value = :desc AND t.default_langcode = 1", [':vid' => $this->config('forum.settings')->get('vocabulary'), ':name' => $name, ':desc' => $description])->fetchAssoc();
$this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
// Verify forum hierarchy.
$tid = $term['tid'];
$parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", [':tid' => $tid])->fetchField();
$this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
catch
committed
$forum = $this->container->get('entity.manager')->getStorage('taxonomy_term')->load($tid);
$this->assertEqual(($type == 'forum container'), (bool) $forum->forum_container->value);
return $term;
}
Angie Byron
committed
/**
Jennifer Hodgdon
committed
* Deletes a forum.
Angie Byron
committed
*
* @param int $tid
Angie Byron
committed
*/
function deleteForum($tid) {
// Delete the forum.
$this->drupalGet('admin/structure/forum/edit/forum/' . $tid);
$this->clickLink(t('Delete'));
Alex Pott
committed
$this->assertText('Are you sure you want to delete the forum');
$this->assertNoText('Add forum');
$this->assertNoText('Add forum container');
$this->drupalPostForm(NULL, [], t('Delete'));
Angie Byron
committed
// Assert that the forum no longer exists.
$this->drupalGet('forum/' . $tid);
Angie Byron
committed
$this->assertResponse(404, 'The forum was not found');
Angie Byron
committed
}
/**
Jennifer Hodgdon
committed
* Runs basic tests on the indicated user.
*
* @param \Drupal\Core\Session\AccountInterface $user
* The logged in user.
* @param bool $admin
* User has 'access administration pages' privilege.
*/
private function doBasicTests($user, $admin) {
// Log in the user.
$this->drupalLogin($user);
// Attempt to create forum topic under a container.
$this->createForumTopic($this->forumContainer, TRUE);
// Create forum node.
$node = $this->createForumTopic($this->forum, FALSE);
// Verify the user has access to all the forum nodes.
Angie Byron
committed
$this->verifyForums($node, $admin);
}
/**
* Tests a forum with a new post displays properly.
*/
function testForumWithNewPost() {
// Log in as the first user.
Alex Pott
committed
$this->drupalLogin($this->adminUser);
// Create a forum container.
$this->forumContainer = $this->createForum('container');
// Create a forum.
$this->forum = $this->createForum('forum');
// Create a topic.
$node = $this->createForumTopic($this->forum, FALSE);
// Log in as a second user.
Alex Pott
committed
$this->drupalLogin($this->postCommentUser);
// Post a reply to the topic.
$edit = [];
Alex Pott
committed
$edit['subject[0][value]'] = $this->randomMachineName();
$edit['comment_body[0][value]'] = $this->randomMachineName();
$this->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
$this->assertResponse(200);
Angie Byron
committed
// Test replying to a comment.
$this->clickLink('Reply');
$this->assertResponse(200);
$this->assertFieldByName('comment_body[0][value]');
// Log in as the first user.
Alex Pott
committed
$this->drupalLogin($this->adminUser);
// Check that forum renders properly.
$this->drupalGet("forum/{$this->forum['tid']}");
$this->assertResponse(200);
// Verify there is no unintentional HTML tag escaping.
$this->assertNoEscaped('<', '');
}
/**
Jennifer Hodgdon
committed
* Creates a forum topic.
*
* @param array $forum
Jennifer Hodgdon
committed
* A forum array.
* @param bool $container
Jennifer Hodgdon
committed
* TRUE if $forum is a container; FALSE otherwise.
*
* @return object
Jennifer Hodgdon
committed
* The created topic node.
*/
function createForumTopic($forum, $container = FALSE) {
// Generate a random subject/body.
Alex Pott
committed
$title = $this->randomMachineName(20);
$body = $this->randomMachineName(200);
$edit = [
'title[0][value]' => $title,
Angie Byron
committed
'body[0][value]' => $body,
];
$tid = $forum['tid'];
Dries Buytaert
committed
// Create the forum topic, preselecting the forum ID via a URL parameter.
$this->drupalPostForm('node/add/forum', $edit, t('Save'), ['query' => ['forum_id' => $tid]]);
Dries Buytaert
committed
$type = t('Forum topic');
if ($container) {
$this->assertNoText(t('@type @title has been created.', ['@type' => $type, '@title' => $title]), 'Forum topic was not created');
$this->assertRaw(t('The item %title is a forum container, not a forum.', ['%title' => $forum['name']]), 'Error message was shown');
return;
}
else {
$this->assertText(t('@type @title has been created.', ['@type' => $type, '@title' => $title]), 'Forum topic was created');
$this->assertNoRaw(t('The item %title is a forum container, not a forum.', ['%title' => $forum['name']]), 'No error message was shown');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
}
Dries Buytaert
committed
// Retrieve node object, ensure that the topic was created and in the proper forum.
$node = $this->drupalGetNodeByTitle($title);
$this->assertTrue($node != NULL, format_string('Node @title was loaded', ['@title' => $title]));
catch
committed
$this->assertEqual($node->taxonomy_forums->target_id, $tid, 'Saved forum topic was in the expected forum');
// View forum topic.
$this->drupalGet('node/' . $node->id());
Dries Buytaert
committed
$this->assertRaw($title, 'Subject was found');
$this->assertRaw($body, 'Body was found');
return $node;
}
/**
Jennifer Hodgdon
committed
* Verifies that the logged in user has access to a forum node.
*
Angie Byron
committed
* @param \Drupal\Core\Entity\EntityInterface $node
* The node being checked.
* @param bool $admin
* Boolean to indicate whether the user can 'access administration pages'.
* @param int $response
Alex Pott
committed
* The expected HTTP response code.
*/
Angie Byron
committed
private function verifyForums(EntityInterface $node, $admin, $response = 200) {
$response2 = ($admin) ? 200 : 403;
// View forum help node.
$this->drupalGet('admin/help/forum');
$this->assertResponse($response2);
if ($response2 == 200) {
Dries Buytaert
committed
$this->assertTitle(t('Forum | Drupal'), 'Forum help title was displayed');
$this->assertText(t('Forum'), 'Forum help node was displayed');
}
// View forum container page.
$this->verifyForumView($this->forumContainer);
// View forum page.
$this->verifyForumView($this->forum, $this->forumContainer);
// View root forum page.
Alex Pott
committed
$this->verifyForumView($this->rootForum);
// View forum node.
$this->drupalGet('node/' . $node->id());
$this->assertResponse(200);
Dries Buytaert
committed
$this->assertTitle($node->label() . ' | Drupal', 'Forum node was displayed');
$breadcrumb_build = [
Angie Byron
committed
Link::createFromRoute(t('Home'), '<front>'),
Link::createFromRoute(t('Forums'), 'forum.index'),
Link::createFromRoute($this->forumContainer['name'], 'forum.page', ['taxonomy_term' => $this->forumContainer['tid']]),
Link::createFromRoute($this->forum['name'], 'forum.page', ['taxonomy_term' => $this->forum['tid']]),
];
$breadcrumb = [
'#theme' => 'breadcrumb',
Angie Byron
committed
'#links' => $breadcrumb_build,
];
$this->assertRaw(\Drupal::service('renderer')->renderRoot($breadcrumb), 'Breadcrumbs were displayed');
// View forum edit node.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertResponse($response);
if ($response == 200) {
Dries Buytaert
committed
$this->assertTitle('Edit Forum topic ' . $node->label() . ' | Drupal', 'Forum edit node was displayed');
}
if ($response == 200) {
// Edit forum node (including moving it to another forum).
$edit = [];
$edit['title[0][value]'] = 'node/' . $node->id();
Alex Pott
committed
$edit['body[0][value]'] = $this->randomMachineName(256);
// Assume the topic is initially associated with $forum.
Alex Pott
committed
$edit['taxonomy_forums'] = $this->rootForum['tid'];
$edit['shadow'] = TRUE;
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->assertText(t('Forum topic @title has been updated.', ['@title' => $edit['title[0][value]']]), 'Forum node was edited');
// Verify topic was moved to a different forum.
$forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", [
':nid' => $node->id(),
':vid' => $node->getRevisionId(),
])->fetchField();
Alex Pott
committed
$this->assertTrue($forum_tid == $this->rootForum['tid'], 'The forum topic is linked to a different forum');
// Delete forum node.
$this->drupalPostForm('node/' . $node->id() . '/delete', [], t('Delete'));
$this->assertResponse($response);
$this->assertRaw(t('Forum topic %title has been deleted.', ['%title' => $edit['title[0][value]']]), 'Forum node was deleted');
}
}
/**
Jennifer Hodgdon
committed
* Verifies the display of a forum page.
*
* @param array $forum
Jennifer Hodgdon
committed
* A row from the taxonomy_term_data table in an array.
* @param array $parent
Jennifer Hodgdon
committed
* (optional) An array representing the forum's parent.
*/
private function verifyForumView($forum, $parent = NULL) {
// View forum page.
$this->drupalGet('forum/' . $forum['tid']);
$this->assertResponse(200);
catch
committed
$this->assertTitle($forum['name'] . ' | Drupal');
$breadcrumb_build = [
Angie Byron
committed
Link::createFromRoute(t('Home'), '<front>'),
Link::createFromRoute(t('Forums'), 'forum.index'),
];
if (isset($parent)) {
$breadcrumb_build[] = Link::createFromRoute($parent['name'], 'forum.page', ['taxonomy_term' => $parent['tid']]);
}
$breadcrumb = [
'#theme' => 'breadcrumb',
Angie Byron
committed
'#links' => $breadcrumb_build,
];
$this->assertRaw(\Drupal::service('renderer')->renderRoot($breadcrumb), 'Breadcrumbs were displayed');
}
/**
* Generates forum topics.
*/
Angie Byron
committed
private function generateForumTopics() {
$this->nids = [];
for ($i = 0; $i < 5; $i++) {
$node = $this->createForumTopic($this->forum, FALSE);
$this->nids[] = $node->id();
}
}