You are here

public function MetatagTagsTestBase::testTagsArePresent in Metatag 7

Tests that this module's tags are available.

File

tests/MetatagTagsTestBase.test, line 72
Base class for testing a module's custom tags.

Class

MetatagTagsTestBase
Base class for testing a module's custom tags.

Code

public function testTagsArePresent() {

  // Load the global config.
  $this
    ->drupalGet('admin/config/search/metatags/config/global');
  $this
    ->assertResponse(200);

  // Confirm the various meta tags are available.
  foreach ($this->tags as $tag) {

    // Convert tag names to something more suitable for a function name.
    $tag_name = str_replace(array(
      '.',
      '-',
      ':',
    ), '_', $tag);

    // Look for a custom method named "{$tag_name}_test_field_xpath", if found
    // use that method to get the xpath definition for this meta tag,
    // otherwise it defaults to just looking for a text input field.
    $method = "{$tag_name}_test_field_xpath";
    if (method_exists($this, $method)) {
      $xpath = $this
        ->{$method}();
    }
    else {
      $xpath = "//input[@name='metatags[und][{$tag}][value]' and @type='text']";
    }
    $this
      ->assertFieldByXPath($xpath, NULL, format_string('The "%tag" tag field was found.', array(
      '%tag' => $tag,
    )));
  }
}