Commit 4803ab50 authored by Naveen Valecha's avatar Naveen Valecha Committed by Naveen Valecha
Browse files

Issue #3248828 by naveenvalecha: Add Automated tests - Custom Meta tags.

parent 922a4288
Loading
Loading
Loading
Loading

composer.json

0 → 100644
+26 −0
Original line number Diff line number Diff line
{
    "name": "drupal/custom_meta",
    "description": "Builds on top of Metatag to deliver extra functionality.",
    "type": "drupal-module",
    "license": "GPL-2.0-or-later",
    "keywords": [
        "Drupal",
        "SEO"
    ],
    "homepage": "https://www.drupal.org/project/custom_meta",
    "authors": [
        {
            "name": "See contributors",
            "homepage": "https://www.drupal.org/node/1788408/committers",
            "role": "Developer"
        }
    ],
    "minimum-stability": "dev",
    "support": {
        "issues": "https://www.drupal.org/project/issues/custom_meta",
        "source": "https://git.drupalcode.org/project/custom_meta"
    },
    "require": {
        "drupal/metatag": "^1.21"
    }
}
+11 −0
Original line number Diff line number Diff line
metatag.metatag_tag.custom_meta_tag_name:*:
  type: text
  label: 'Custom name Meta tag'

metatag.metatag_tag.custom_meta_tag_property:*:
  type: text
  label: 'Custom property Meta tag'

metatag.metatag_tag.custom_meta_tag_http_equiv:*:
  type: text
  label: 'Custom http-equiv Meta tag'
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ custom_meta.settings:
        mapping:
          attribute:
            type: string
            label: 'Name'
            label: 'Attribute'
            description: 'The attribute of the meta tag.'
          name:
            type: string
+0 −1
Original line number Diff line number Diff line
@@ -8,5 +8,4 @@ dependencies:
  - metatag:metatag

test_dependencies:
  - token:token
  - metatag:metatag
+18 −80
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ use Drupal\Tests\BrowserTestBase;
 */
class CustomMetaAdminTest extends BrowserTestBase {

  use CustomMetaHelperTrait;

  /**
   * {@inheritdoc}
   */
@@ -43,103 +45,39 @@ class CustomMetaAdminTest extends BrowserTestBase {
      ->drupalCreateUser([
        'administer custom meta tags',
      ]);
    $this->drupalLogin($this->adminUser);
  }

  /**
   * Tests the custom meta administration end to end.
   */
  public function testCustomMeta() {
    // Initiate session with a user who can manage custom metatags.
    $this->drupalLogin($this->adminUser);

    // Access custom meta settings page.
    $this->customMetaSettingsFormTest();

    // Access custom meta listing page.
    $this->customMetaListingPageTest();

    // Update custom meta settings without prefix.
    $this->updateCustomMetaSettingsWithoutPrefix();
    // Check custom meta listing empty text.
    $this->customMetaListingEmptyText();
    // Access custom meta listing page operations for name type.
    $this->customMetaListingPageOperationsTest('name');
    $this->customMetaListingPageOperations('name');
    // Access custom meta listing page operations for property type.
    $this->customMetaListingPageOperationsTest('property');
    $this->customMetaListingPageOperations('property');
    // Access custom meta listing page operations for http-equiv type.
    $this->customMetaListingPageOperationsTest('http-equiv');
    $this->customMetaListingPageOperations('http-equiv');
  }

  /**
   * Test custom meta configuration form test.
   * Test custom meta listing page operations.
   *
   * @throws \Behat\Mink\Exception\ElementNotFoundException
   * @throws \Behat\Mink\Exception\ExpectationException
   * @throws \Behat\Mink\Exception\ResponseTextException
   */
  public function customMetaSettingsFormTest() {
    $this->drupalGet('admin/config/search/metatag/custom-meta/settings');
    $this->assertSession()->statusCodeEquals(200);
    $this->submitForm([], 'Save configuration');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('The configuration options have been saved.');
    $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta/settings');
  }

  /**
   * Test custom meta listing page test.
   *
   * @throws \Behat\Mink\Exception\ElementNotFoundException
   * @throws \Behat\Mink\Exception\ExpectationException
   * @throws \Behat\Mink\Exception\ResponseTextException
   */
  public function customMetaListingPageTest() {
    $this->drupalGet('admin/config/search/metatag/custom-meta');
    $this->assertSession()->statusCodeEquals(200);
    // Check that the Add tag link exists.
    $this->assertSession()->linkByHrefExists('admin/config/search/metatag/custom-meta/add');
    // Check that empty message exists.
    $this->assertSession()->pageTextContains('No custom meta tags available.');
  }

  /**
   * Test custom meta listing page operations test.
   *
   * @throws \Behat\Mink\Exception\ElementNotFoundException
   * @throws \Behat\Mink\Exception\ExpectationException
   * @throws \Behat\Mink\Exception\ResponseTextException
   */
  public function customMetaListingPageOperationsTest($attribute) {
    // Access custom meta add page.
    $this->drupalGet('admin/config/search/metatag/custom-meta/add');
    $this->assertSession()->statusCodeEquals(200);
    $edit = [];
    $edit['attribute'] = $attribute;
    $edit['name'] = 'nid';
    $edit['label'] = 'Nid';
    $edit['description'] = 'Nid description';
    $this->submitForm($edit, 'Save');
    $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta');
    $this->assertSession()->pageTextContains('Meta tag has been saved.');

    // Access custom meta edit page.
    $this->drupalGet('admin/config/search/metatag/custom-meta/edit/' . $edit['name']);
    $this->assertSession()->statusCodeEquals(200);
    $this->submitForm(['description' => 'Node id description'], 'Save');
    $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta');
    $this->assertSession()->pageTextContains('Meta tag has been saved.');

    // Access custom meta delete page and perform cancel operation.
    $this->drupalGet('admin/config/search/metatag/custom-meta/delete/' . $edit['name']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Are you sure you want to delete custom meta tag Nid?');
    $this->clickLink('Cancel');
    $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta');
    $this->assertSession()->pageTextContains('Node id description');

    // Access custom meta delete page and perform delete operation.
    $this->drupalGet('admin/config/search/metatag/custom-meta/delete/' . $edit['name']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Are you sure you want to delete custom meta tag Nid?');
    $this->submitForm([], 'Confirm');
    $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta');
    $this->assertSession()->pageTextNotContains('Node id description');
  public function customMetaListingPageOperations($attribute) {
    // Create custom meta tag.
    $this->createCustomMetaTag($attribute);
    // Update custom meta tag.
    $this->updateCustomMetaTag();
    // Delete custom meta tag.
    $this->deleteCustomMetaTag();
  }

}
Loading