Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / metatag / src / Tests / MetatagAdminTest.php
index dd3f66107f188e1cf3b44dba1be11be1777ccd6f..fe662796b1f4988ba52d3cfa2fbc0c4706d9d9c8 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Drupal\metatag\Tests;
 
+use Drupal\metatag\MetatagManager;
 use Drupal\simpletest\WebTestBase;
 
 /**
@@ -74,8 +75,8 @@ class MetatagAdminTest extends WebTestBase {
     $this->assertLinkByHref('admin/config/search/metatag/global', 0, t('Global defaults were created on installation.'));
 
     // Check that Global and entity defaults can't be deleted.
-    $this->assertNoLinkByHref('admin/config/search/metatag/global/delete', 0, t('Global defaults can\'t be deleted'));
-    $this->assertNoLinkByHref('admin/config/search/metatag/node/delete', 0, t('Entity defaults can\'t be deleted'));
+    $this->assertNoLinkByHref('admin/config/search/metatag/global/delete', 0, t("Global defaults can't be deleted"));
+    $this->assertNoLinkByHref('admin/config/search/metatag/node/delete', 0, t("Entity defaults can't be deleted"));
 
     // Check that the module defaults were injected into the Global config
     // entity.
@@ -168,8 +169,7 @@ class MetatagAdminTest extends WebTestBase {
     $types = [];
     foreach ($xpath[0]->children() as $item) {
       if (!empty($item->option)) {
-        $data = (array)$item->option;
-        // $this->verbose('<pre>' . print_r($data, TRUE) . '</pre>');
+        $data = (array) $item->option;
         $types[$data['@attributes']['value']] = $data[0];
       }
     }
@@ -275,10 +275,8 @@ class MetatagAdminTest extends WebTestBase {
       $this->assertRaw($value, t('Node metatag @tag overrides Global defaults.', ['@tag' => $metatag]));
     }
 
-    /**
-     * Check that when the node defaults don't define a metatag, the Global one
-     * is used.
-     */
+    // Check that when the node defaults don't define a metatag, the Global one
+    // is used.
     // First unset node defaults.
     $this->drupalGet('admin/config/search/metatag/node');
     $this->assertResponse(200);
@@ -304,7 +302,7 @@ class MetatagAdminTest extends WebTestBase {
     // return cached results.
     // @todo BookTest.php resets the cache of a single node, which is way more
     // performant than creating a node for every set of assertions.
-    // @see BookTest::testDelete().
+    // @see BookTest::testDelete()
     $node = $this->drupalCreateNode([
       'title' => t('Hello, world!'),
       'type' => 'article',
@@ -346,11 +344,12 @@ class MetatagAdminTest extends WebTestBase {
   }
 
   /**
-   * Test that the entity default values load on the entity form, and that they
-   * can then be overridden correctly.
+   * Test that the entity default values load on the entity form.
+   *
+   * And that they can then be overridden correctly.
    */
   public function testEntityDefaultInheritence() {
-    // Initiate session with a user who can manage metatags and content type
+    // Initiate session with a user who can manage meta tags and content type
     // fields.
     $permissions = [
       'administer site configuration',
@@ -404,4 +403,42 @@ class MetatagAdminTest extends WebTestBase {
     $this->assertFieldByName('field_meta_tags[0][basic][description]', 'Article description override');
   }
 
+  /**
+   * Test that protected Metatag defaults cannot be deleted.
+   */
+  public function testDefaultProtected() {
+    // Initiate session with a user who can manage metatags.
+    $permissions = ['administer site configuration', 'administer meta tags'];
+    $account = $this->drupalCreateUser($permissions);
+    $this->drupalLogin($account);
+
+    // Add default metatag for Articles.
+    $edit = [
+      'id' => 'node__article',
+    ];
+    $this->drupalPostForm('/admin/config/search/metatag/add', $edit, 'Save');
+
+    // Check that protected defaults contains "Revert" link instead of "Delete".
+    foreach (MetatagManager::protectedDefaults() as $protected) {
+      $this->assertLinkByHref('/admin/config/search/metatag/' . $protected);
+      $this->assertLinkByHref('/admin/config/search/metatag/' . $protected . '/revert');
+      $this->assertNoLinkByHref('/admin/config/search/metatag/' . $protected . '/delete');
+    }
+
+    // Confirm that non protected defaults can be deleted.
+    $this->assertLinkByHref('/admin/config/search/metatag/node__article');
+    $this->assertNoLinkByHref('/admin/config/search/metatag/node__article/revert');
+    $this->assertLinkByHref('/admin/config/search/metatag/node__article/delete');
+
+    // Visit each protected default page to confirm "Delete" button is hidden.
+    foreach (MetatagManager::protectedDefaults() as $protected) {
+      $this->drupalGet('/admin/config/search/metatag/' . $protected);
+      $this->assertNoLink('Delete');
+    }
+
+    // Confirm that non protected defaults can be deleted.
+    $this->drupalGet('/admin/config/search/metatag/node__article');
+    $this->assertLink('Delete');
+  }
+
 }