diff --git a/core/modules/forum/src/Form/ContainerForm.php b/core/modules/forum/src/Form/ContainerForm.php index 226cd31..dd2fb3c 100644 --- a/core/modules/forum/src/Form/ContainerForm.php +++ b/core/modules/forum/src/Form/ContainerForm.php @@ -28,7 +28,6 @@ public function form(array $form, FormStateInterface $form_state) { $taxonomy_term = $this->entity; // Build the bulk of the form from the parent forum form. $form = parent::form($form, $form_state, $taxonomy_term); - $this->forumFormType = $this->t('forum container'); // Update the description. @@ -54,7 +53,17 @@ public function prepareEntity() { // Set the title and description of the name field. $this->entity->get('name')->getDataDefinition()->setLabel('Container name'); $this->entity->get('name')->getDataDefinition()->setDescription('Short but meaningful name for this collection of related forums.'); - // Change the description. - $this->entity->get('description')->getDataDefinition()->setDescription('Containers are usually placed at the top (root) level, but may also be placed inside another container or forum.'); } + + /** + * {@inheritdoc} + */ + protected function forumParentSelect($tid, $title) { + $parent_select = parent::forumParentSelect($tid, $title); + // Change the description of the parent select. + $parent_select['#description'] = $this->t('Containers are usually placed at the top (root) level, but may also be placed inside another container or forum.'); + + return $parent_select; + } + } diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php index c6d277b..72d189c 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -41,7 +41,7 @@ public function form(array $form, FormStateInterface $form_state) { // Re-use the weight field. $form['weight'] = $form['relations']['weight']; // But update the description. - $form['weight']['#description'] = $this->t('Forums are displayed in ascending order by weight.'); + $form['weight']['#description'] = $this->t('Forums are displayed in ascending order by weight.Forums are displayed in ascending order by weight.'); // Remove the remaining relations fields. unset($form['relations']); diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index e75507a..1cf589d 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -16,8 +16,7 @@ use Drupal\taxonomy\Entity\Vocabulary; /** - * Create, view, edit, delete, and change forum entries and verify its - * consistency in the database. + * Verifies CRUD operations on the forum entries. * * @group forum */ @@ -28,7 +27,15 @@ class ForumTest extends WebTestBase { * * @var array */ - public static $modules = array('taxonomy', 'comment', 'forum', 'node', 'block', 'menu_ui', 'help'); + public static $modules = array( + 'taxonomy', + 'comment', + 'forum', + 'node', + 'block', + 'menu_ui', + 'help', + ); /** * A user with various administrative privileges. @@ -113,11 +120,11 @@ protected function setUp() { /** * Tests forum functionality through the admin and user interfaces. */ - function testForum() { - //Check that the basic forum install creates a default forum topic + protected function testForum() { + // Check that the basic forum install creates a default forum topic. $this->drupalGet('/forum'); - // Look for the "General discussion" default forum - $this->assertRaw(t('General discussion'), "Found the default forum at the /forum listing"); + // Look for the "General discussion" default forum. + $this->assertRaw(t('General discussion', array('!url' => Url::fromRoute('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'); @@ -207,7 +214,15 @@ function testForum() { $this->assertFieldByXPath($xpath, '6', 'Number of posts found.'); // Test loading multiple forum nodes on the front page. - $this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content', 'post comments'))); + $this->drupalLogin( + $this->drupalCreateUser( + array( + 'administer content types', + 'create forum content', + 'post comments', + ) + ) + ); $this->drupalPostForm('admin/structure/types/manage/forum', array('options[promote]' => 'promote'), t('Save content type')); $this->createForumTopic($this->forum, FALSE); $this->createForumTopic($this->forum, FALSE); @@ -247,7 +262,7 @@ function testForum() { * Verifies that forum nodes are not created without choosing "forum" from the * select list. */ - function testAddOrphanTopic() { + protected function testAddOrphanTopic() { // Must remove forum topics to test creating orphan topics. $vid = $this->config('forum.settings')->get('vocabulary'); $tids = \Drupal::entityQuery('taxonomy_term') @@ -347,12 +362,16 @@ private function doAdminTests($user) { // Test relations widget exists. $relations_widget = $this->xpath("//details[@id='edit-relations']"); $this->assertTrue(isset($relations_widget[0]), 'Relations widget element found.'); + // Test for forum specific descriptions and labels. + $this->verifyForumForm('forum'); + // Test for container specific descriptions and labels. + $this->verifyForumForm('container'); } /** * Edits the forum taxonomy. */ - function editForumVocabulary() { + protected function editForumVocabulary() { // Backup forum taxonomy. $vid = $this->config('forum.settings')->get('vocabulary'); $original_vocabulary = Vocabulary::load($vid); @@ -387,15 +406,15 @@ function editForumVocabulary() { /** * Creates a forum container or a forum. * - * @param $type + * @param string $type * The forum type (forum container or forum). - * @param $parent + * @param int $parent * The forum parent. This defaults to 0, indicating a root forum. * - * @return + * @return object * The created taxonomy term data. */ - function createForum($type, $parent = 0) { + protected function createForum($type, $parent = 0) { // Generate a random name/description. $name = $this->randomMachineName(10); $description = $this->randomMachineName(100); @@ -414,7 +433,7 @@ function createForum($type, $parent = 0) { $this->assertRaw( t( 'Created new @type %term.', - array('%term' => $name, '@type' => t($type)) + array('%term' => $name, '@type' => $type) ), format_string('@type was created', array('@type' => ucfirst($type))) ); @@ -436,10 +455,10 @@ function createForum($type, $parent = 0) { /** * Deletes a forum. * - * @param $tid + * @param int $tid * The forum ID. */ - function deleteForum($tid) { + protected function deleteForum($tid) { // Delete the forum. $this->drupalGet('admin/structure/forum/edit/forum/' . $tid); $this->clickLink(t('Delete')); @@ -456,9 +475,9 @@ function deleteForum($tid) { /** * Runs basic tests on the indicated user. * - * @param $user + * @param object $user * The logged in user. - * @param $admin + * @param bool $admin * User has 'access administration pages' privilege. */ private function doBasicTests($user, $admin) { @@ -475,7 +494,7 @@ private function doBasicTests($user, $admin) { /** * Tests a forum with a new post displays properly. */ - function testForumWithNewPost() { + protected function testForumWithNewPost() { // Login as the first user. $this->drupalLogin($this->admin_user); // Create a forum container. @@ -511,13 +530,13 @@ function testForumWithNewPost() { * * @param array $forum * A forum array. - * @param boolean $container + * @param bool $container * TRUE if $forum is a container; FALSE otherwise. * * @return object * The created topic node. */ - function createForumTopic($forum, $container = FALSE) { + protected function createForumTopic($forum, $container = FALSE) { // Generate a random subject/body. $title = $this->randomMachineName(20); $body = $this->randomMachineName(200); @@ -542,7 +561,8 @@ function createForumTopic($forum, $container = FALSE) { $this->assertNoRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), 'No error message was shown'); } - // Retrieve node object, ensure that the topic was created and in the proper forum. + // 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', array('@title' => $title))); $this->assertEqual($node->taxonomy_forums->target_id, $tid, 'Saved forum topic was in the expected forum'); @@ -560,9 +580,9 @@ function createForumTopic($forum, $container = FALSE) { * * @param \Drupal\Core\Entity\EntityInterface $node * The node being checked. - * @param $admin + * @param bool $admin * Boolean to indicate whether the user can 'access administration pages'. - * @param $response + * @param int $response * The exptected HTTP response code. */ private function verifyForums(EntityInterface $node, $admin, $response = 200) { @@ -634,9 +654,9 @@ private function verifyForums(EntityInterface $node, $admin, $response = 200) { /** * Verifies the display of a forum page. * - * @param $forum + * @param array $forum * A row from the taxonomy_term_data table in an array. - * @param $parent + * @param array $parent * (optional) An array representing the forum's parent. */ private function verifyForumView($forum, $parent = NULL) { @@ -670,4 +690,34 @@ private function generateForumTopics() { $this->nids[] = $node->id(); } } + + /** + * Verifies if forum form descriptions and labels are correct. + * + * @param string $type + * The forum type (forum container or forum). + */ + protected function verifyForumForm($type) { + $this->drupalGet('admin/structure/forum/add/' . $type); + switch ($type) { + case 'forum': + $this->assertRaw('Forum name', 'Forum title field label found'); + $this->assertRaw('Short but meaningful name for this collection of threaded discussions.', 'Forum title field description found.'); + $this->assertRaw('Forums are displayed in ascending order by weight.', 'Forum weight field description found.'); + $this->assertRaw('Description and guidelines for discussions within this forum.', 'Forum description field description found.'); + break; + + case 'container': + $this->assertRaw('Container name', 'Container title field label found.'); + $this->assertRaw('Short but meaningful name for this collection of related forums.', 'Container title field description found.'); + $this->assertRaw('Containers are displayed in ascending order by weight.', 'Container weight field description found.'); + $this->assertRaw('Containers are usually placed at the top (root) level, but may also be placed inside another container or forum.', 'Container parent field description found.'); + $this->assertRaw('Description and guidelines for discussions within this forum.', 'Container description field description found.'); + break; + + default: + break; + } + } + }