Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / metatag / src / Tests / MetatagFrontpageTest.php
index 5e42a3169c52600b6b8c3418f4e94138f95bc068..a360432c9b44b180aa07e0c7edd5d5500facde1d 100644 (file)
@@ -5,12 +5,17 @@ namespace Drupal\metatag\Tests;
 use Drupal\simpletest\WebTestBase;
 
 /**
- * Ensures that metatags are rendering correctly on home page.
+ * Ensures that meta tags are rendering correctly on home page.
  *
  * @group metatag
  */
 class MetatagFrontpageTest extends WebTestBase {
 
+  // Use the helper functions from the Functional trait. This is pretty safe but
+  // remember to rewrite all of these WebTestBase tests using BrowserTestBase
+  // before the next millenium.
+  use MetatagHelperTrait;
+
   /**
    * {@inheritdoc}
    */
@@ -29,31 +34,14 @@ class MetatagFrontpageTest extends WebTestBase {
    */
   protected $nodeId;
 
-  /**
-   * Administrator user for tests.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $adminUser;
-
   /**
    * Setup basic environment.
    */
   protected function setUp() {
     parent::setUp();
 
-    $admin_permissions = [
-      'administer content types',
-      'administer nodes',
-      'bypass node access',
-      'administer meta tags',
-      'administer site configuration',
-      'access content',
-    ];
-
-    // Create and login user.
-    $this->adminUser = $this->drupalCreateUser($admin_permissions);
-    $this->drupalLogin($this->adminUser);
+    // Login user 1.
+    $this->loginUser1();
 
     // Create content type.
     $this->drupalCreateContentType(['type' => 'page', 'display_submitted' => FALSE]);
@@ -70,23 +58,21 @@ class MetatagFrontpageTest extends WebTestBase {
    * The front page config is enabled, its meta tags should be used.
    */
   public function testFrontPageMetatagsEnabledConfig() {
-    $this->drupalLogin($this->adminUser);
-
     // Add something to the front page config.
     $this->drupalGet('admin/config/search/metatag/front');
     $this->assertResponse(200);
-    $values = [
+    $edit = [
       'title' => 'Test title',
       'description' => 'Test description',
-      'keywords' => 'testing,keywords'
+      'keywords' => 'testing,keywords',
     ];
-    $this->drupalPostForm(NULL, $values, t('Save'));
+    $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertResponse(200);
     $this->assertText(t('Saved the Front page Metatag defaults.'));
 
     // Testing front page metatags.
     $this->drupalGet('<front>');
-    foreach ($values as $metatag => $metatag_value) {
+    foreach ($edit as $metatag => $metatag_value) {
       $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
       $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
       $value = (string) $xpath[0]['content'];
@@ -96,7 +82,7 @@ class MetatagFrontpageTest extends WebTestBase {
     $node_path = '/node/' . $this->nodeId;
     // Testing front page metatags.
     $this->drupalGet($node_path);
-    foreach ($values as $metatag => $metatag_value) {
+    foreach ($edit as $metatag => $metatag_value) {
       $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
       $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
       $value = (string) $xpath[0]['content'];
@@ -104,14 +90,19 @@ class MetatagFrontpageTest extends WebTestBase {
     }
 
     // Change the front page to a valid custom route.
-    $edit['site_frontpage'] = '/test-page';
+    $site_edit = [
+      'site_frontpage' => '/test-page',
+    ];
     $this->drupalGet('admin/config/system/site-information');
     $this->assertResponse(200);
-    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
+    $this->drupalPostForm(NULL, $site_edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), 'The front page path has been saved.');
+    return;
 
+    // @todo Finish this?
     $this->drupalGet('test-page');
-    foreach ($values as $metatag => $metatag_value) {
+    $this->assertResponse(200);
+    foreach ($edit as $metatag => $metatag_value) {
       $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
       $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
       $value = (string) $xpath[0]['content'];
@@ -120,7 +111,7 @@ class MetatagFrontpageTest extends WebTestBase {
   }
 
   /**
-   * Test front page metatags when front page config is disabled.
+   * Test front page meta tags when front page config is disabled.
    */
   public function testFrontPageMetatagDisabledConfig() {
     // Disable front page metatag, enable node metatag & check.
@@ -133,42 +124,44 @@ class MetatagFrontpageTest extends WebTestBase {
     // Update the Metatag Node defaults.
     $this->drupalGet('admin/config/search/metatag/node');
     $this->assertResponse(200);
-    $values = [
+    $edit = [
       'title' => 'Test title for a node.',
       'description' => 'Test description for a node.',
     ];
-    $this->drupalPostForm(NULL, $values, 'Save');
+    $this->drupalPostForm(NULL, $edit, 'Save');
     $this->assertText('Saved the Content Metatag defaults.');
     $this->drupalGet('<front>');
-    foreach ($values as $metatag => $metatag_value) {
+    foreach ($edit as $metatag => $metatag_value) {
       $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
       $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
       $value = (string) $xpath[0]['content'];
       $this->assertEqual($value, $metatag_value);
     }
 
+    // Change the front page to a valid path.
+    $this->drupalGet('admin/config/system/site-information');
+    $this->assertResponse(200);
+    $edit = [
+      'site_frontpage' => '/test-page',
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'), 'The front page path has been saved.');
+
     // Front page is custom route.
     // Update the Metatag Node global.
     $this->drupalGet('admin/config/search/metatag/global');
     $this->assertResponse(200);
-    $values = [
+    $edit = [
       'title' => 'Test title.',
       'description' => 'Test description.',
     ];
-    $this->drupalPostForm(NULL, $values, 'Save');
+    $this->drupalPostForm(NULL, $edit, 'Save');
     $this->assertText('Saved the Global Metatag defaults.');
 
-    // Change the front page to a valid path.
-    $this->drupalGet('admin/config/system/site-information');
-    $this->assertResponse(200);
-    $edit['site_frontpage'] = '/test-page';
-    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
-    $this->assertText(t('The configuration options have been saved.'), 'The front page path has been saved.');
-
     // Test Metatags.
     $this->drupalGet('test-page');
     $this->assertResponse(200);
-    foreach ($values as $metatag => $metatag_value) {
+    foreach ($edit as $metatag => $metatag_value) {
       $xpath = $this->xpath("//meta[@name='" . $metatag . "']");
       $this->assertEqual(count($xpath), 1, 'Exactly one ' . $metatag . ' meta tag found.');
       $value = (string) $xpath[0]['content'];