662cfc9421323297d4bcf540fcec80315052aa49
[yaffs-website] / web / modules / contrib / metatag / src / Tests / MetatagForumTest.php
1 <?php
2
3 namespace Drupal\metatag\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6
7 /**
8  * Ensures that meta tags are rendering correctly on forum pages.
9  *
10  * @group metatag
11  */
12 class MetatagForumTest extends WebTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = [
18     'token',
19     'metatag',
20     'node',
21     'system',
22     'forum',
23   ];
24
25   /**
26    * Administrator user for tests.
27    *
28    * @var \Drupal\user\UserInterface
29    */
30   protected $adminUser;
31
32   /**
33    * Setup basic environment.
34    */
35   protected function setUp() {
36     parent::setUp();
37
38     $admin_permissions = [
39       'administer nodes',
40       'bypass node access',
41       'administer meta tags',
42       'administer site configuration',
43       'access content',
44     ];
45
46     // Create and login user.
47     $this->adminUser = $this->drupalCreateUser($admin_permissions);
48     $this->drupalLogin($this->adminUser);
49
50     // Create content type.
51     $this->drupalCreateContentType(['type' => 'page', 'display_submitted' => FALSE]);
52     $this->nodeId = $this->drupalCreateNode(
53       [
54         'title' => $this->randomMachineName(8),
55         'promote' => 1,
56       ])->id();
57
58     $this->config('system.site')->set('page.front', '/node/' . $this->nodeId)->save();
59   }
60
61   /**
62    * Verify that a forum post can be loaded when Metatag is enabled.
63    */
64   public function testForumPost() {
65     $this->drupalGet('node/add/forum');
66     $this->assertResponse(200);
67     $edit = [
68       'title[0][value]' => 'Testing forums',
69       'taxonomy_forums' => 1,
70       'body[0][value]' => 'Just testing.',
71     ];
72     $save_label = (floatval(\Drupal::VERSION) <= 8.3) ? t('Save and publish') : t('Save');
73     $this->drupalPostForm(NULL, $edit, $save_label);
74     $this->assertResponse(200);
75     $this->assertText(t('@type @title has been created.', ['@type' => t('Forum topic'), '@title' => 'Testing forums']));
76   }
77
78 }