You are here

abstract class MetatagTestBase in Metatag 7

A base class for the Metatag tests, provides shared methods.

Hierarchy

Expanded class hierarchy of MetatagTestBase

File

tests/MetatagTestBase.test, line 11
A base class for the Metatag tests, provides shared methods.

View source
abstract class MetatagTestBase extends DrupalWebTestCase {

  /**
   * {@inheritdoc}
   */
  public function setUp(array $modules = array()) {

    // Make sure these modules are enabled so that we can use their entity
    // types later.
    $modules[] = 'node';
    $modules[] = 'taxonomy';

    // Requirements.
    $modules[] = 'ctools';
    $modules[] = 'token';

    // Used for the tests.
    $modules[] = 'devel';
    $modules[] = 'devel_generate';

    // Metatag modules. Only enable the main module, submodules will be tested
    // separately.
    $modules[] = 'metatag';

    // Adds some functionality for testing the entity handling.
    $modules[] = 'metatag_test';
    parent::setUp($modules);
  }

  /**
   * {@inheritdoc}
   */
  protected function verbose($message, $title = NULL) {

    // Handle arrays, objects, etc.
    if (!is_string($message)) {
      $message = "<pre>\n" . print_r($message, TRUE) . "\n</pre>\n";
    }

    // Optional title to go before the output.
    if (!empty($title)) {
      $title = '<h2>' . check_plain($title) . "</h2>\n";
    }
    parent::verbose($title . $message);
  }

  /**
   * Load the Performance admin page and clear all caches.
   */
  public function clearAllCaches() {
    $this
      ->drupalGet('admin/config/development/performance');
    $this
      ->assertResponse(200);
    $this
      ->assertText(t('Performance'));
    $this
      ->assertText(t('Clear cache'));
    $this
      ->drupalPost(NULL, array(), t('Clear all caches'));
    $this
      ->assertResponse(200);
    $this
      ->assertText(t('Caches cleared'));
  }

  /**
   * Create a content type for the tests.
   *
   * @param string $machine_name
   *   The machine name of a content type to create.
   * @param string $label
   *   The human-readable name of the content type.
   *
   * @return array
   *   The content type definition.
   */
  public function createContentType($machine_name, $label) {

    // Create a content type.
    $content_type = $this
      ->drupalCreateContentType(array(
      'type' => $machine_name,
      'name' => $label,
    ));

    // Enable meta tags for this new content type.
    metatag_entity_type_enable('node', $machine_name, TRUE);
    return $content_type;
  }

  /**
   * Create an admin user for the tests.
   *
   * @param array $extra_permissions
   *   An array of permission strings to be added to the user.
   *
   * @return object
   *   A user object.
   */
  public function createAdminUser(array $extra_permissions = array()) {
    $permissions = array(
      // Basic permissions for the module.
      'administer meta tags',
      'edit meta tags',
      // General admin access.
      'access administration pages',
    );

    // Reset the static variable used to identify permissions, otherwise it's
    // possible the permissions check in drupalCreateUser will fail.
    $this
      ->checkPermissions(array(), TRUE);
    cache_clear_all();
    return $this
      ->drupalCreateUser(array_merge($permissions, $extra_permissions));
  }

  /**
   * Create a normal user for the tests.
   *
   * @param array $extra_permissions
   *   An array of permission strings to be added to the user.
   *
   * @return object
   *   A user object.
   */
  public function createUser(array $extra_permissions) {

    // Basic permissions for the module.
    $permissions = array(
      'edit meta tags',
    );

    // Reset the static variable used to identify permissions, otherwise it's
    // possible the permissions check in drupalCreateUser will fail.
    $this
      ->checkPermissions(array(), TRUE);
    cache_clear_all();
    return $this
      ->drupalCreateUser(array_merge($permissions, $extra_permissions));
  }

  /**
   * Returns a new vocabulary with random properties.
   *
   * @param string $vocab_name
   *   If empty a random string will be used.
   * @param string $content_type
   *   Any content types listed will have a Taxonomy Term reference field added
   *   that points to the new vocabulary.
   *
   * @return object
   *   A vocabulary object.
   */
  public function createVocabulary($vocab_name = NULL, $content_type = NULL) {
    if (empty($vocab_name)) {
      $vocab_name = $this
        ->randomName();
    }

    // Create a vocabulary.
    $vocabulary = new stdClass();
    $vocabulary->name = $vocab_name;
    $vocabulary->description = $vocab_name;
    $vocabulary->machine_name = drupal_strtolower($vocab_name);
    $vocabulary->help = '';
    $vocabulary->weight = mt_rand(0, 10);
    if (!empty($content_type)) {
      $vocabulary->nodes = array(
        $content_type => $content_type,
      );
    }
    taxonomy_vocabulary_save($vocabulary);

    // Enable meta tags for this new vocabulary.
    metatag_entity_type_enable('taxonomy_term', $vocab_name, TRUE);
    return $vocabulary;
  }

  /**
   * Returns a new taxonomy term in a specific vocabulary.
   *
   * @param object $vocabulary
   *   The vocabulary to add the term to.
   * @param string $term_name
   *   The name to use for the new vocabulary. If none is provided one will be
   *   generated randomly.
   *
   * @return object
   *   A taxonomy term object.
   */
  public function createTerm($vocabulary, $term_name = NULL) {
    if (empty($term_name)) {
      $term_name = $this
        ->randomName();
    }

    // Create an object to save.
    $term = new stdClass();
    $term->name = $term_name;
    $term->description = $term_name;

    // Use the first available text format.
    $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)
      ->fetchField();
    $term->vid = $vocabulary->vid;

    // Save the term.
    taxonomy_term_save($term);
    return $term;
  }

  /**
   * Return an list of default values.
   *
   * This should cover all of the default meta tags provided for a test:foo
   * entity.
   *
   * @return array
   *   List of meta tag default values to test.
   *
   * @todo Expand to cover more meta tags.
   *
   * @see metatag_test_metatag_config_default()
   */
  public function getTestDefaults() {
    return array(
      // Basic meta tags.
      'title' => array(
        'value' => 'Test altered title',
      ),
      'description' => array(
        'value' => 'Test foo description',
      ),
      'abstract' => array(
        'value' => 'Test foo abstract',
      ),
      // @code
      // 'keywords' => array('value' => ''),
      // @endcode
      // Advanced meta tags.
      // @code
      // 'robots' => array('value' => ''),
      // 'news_keywords' => array('value' => ''),
      // 'standout' => array('value' => ''),
      // 'robots' => array('value' => ''),
      // 'standout' => array('value' => ''),
      // @endcode
      'generator' => array(
        'value' => 'Drupal 7 (https://www.drupal.org)',
      ),
      // @code
      // 'standout' => array('value' => ''),
      // 'image_src' => array('value' => ''),
      // @endcode
      'canonical' => array(
        'value' => '[current-page:url:absolute]',
      ),
      'shortlink' => array(
        'value' => '[current-page:url:unaliased]',
      ),
    );
  }

  /**
   * Add a locale to the site.
   *
   * This assumes the Locale module is enabled.
   *
   * @param string $langcode
   *   The language code to add.
   */
  public function addSiteLanguage($langcode) {

    // Load the language-add page.
    $this
      ->drupalGet('admin/config/regional/language/add');
    $this
      ->assertResponse(200, 'Loaded the language-add admin page.');

    // Submit the language-add form.
    $args = array(
      'langcode' => $langcode,
    );
    $this
      ->drupalPost(NULL, $args, t('Add language'));
    $this
      ->assertResponse(200);

    // Verify that the browser was returned to the main languages admin page.
    $this
      ->assertEqual($this
      ->getUrl(), url('admin/config/regional/language', array(
      'absolute' => TRUE,
    )), 'Redirected back to the main languages admin page.');

    // Clear the language list cache so it can be reloaded.
    drupal_static_reset('language_list');

    // Get all language definitions.
    $languages = language_list();
    $language = $languages[$langcode]->name;
    $this
      ->assertText(strip_tags(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array(
      '%language' => t($language),
      '@locale-help' => url('admin/help/locale'),
    ))), 'A new language has been added.');
  }

  /**
   * Set up a basic starting point for the locales.
   *
   * This assumes the Locale module is enabled. This also must be done before
   * other user accounts are logged in.
   *
   * @param array $locales
   *   A list of locales to be enabled, in langcode format.
   */
  public function setupLocales(array $locales = array()) {

    // If no locales were requested, add Spanish and French.
    if (empty($locales)) {
      $locales[] = 'es';
      $locales[] = 'fr';
    }

    // Log in as an admin user with privs to just set up the locales.
    $perms = array(
      'administer languages',
      'translate interface',
      'access administration pages',
    );
    $admin_user = $this
      ->drupalCreateUser($perms);
    $this
      ->drupalLogin($admin_user);

    // Load the admin page, just to have a point of reference.
    $this
      ->drupalGet('admin');
    $this
      ->assertResponse(200, 'Loaded the main admin page.');

    // Identify the site's default language.
    $default_language = language_default('language');

    // Add the locales.
    foreach ($locales as $langcode) {

      // Don't create the default language, it's already present.
      if ($langcode != $default_language) {
        $this
          ->addSiteLanguage($langcode);
      }
    }

    // Enable URL language detection and selection.
    $this
      ->drupalGet('admin/config/regional/language/configure');
    $this
      ->assertResponse(200);
    $edit = array(
      'language[enabled][locale-url]' => TRUE,
    );

    // Also enable path handling for Entity Translation if it is installed.
    if (module_exists('entity_translation')) {
      $edit['language_content[enabled][locale-url]'] = TRUE;
    }
    $this
      ->drupalPost(NULL, $edit, t('Save settings'));
    $this
      ->assertResponse(200);

    // Once all the setup is done, log out the user.
    $this
      ->drupalLogout();
  }

  /**
   * Get the {locales_source} lid value for a specific context.
   *
   * @param string $context
   *   The context string to search for.
   * @param string $textgroup
   *   This string's textgroup; defaults to 'metatag'.
   *
   * @return int
   *   The {locales_source}.lid value for this string.
   */
  public function getTranslationLidByContext($context, $textgroup = 'metatag') {

    // Extra debug output.
    $this
      ->debugLocalesSourcesByContext($context);

    // Look for the string that's actually being requested.
    return (int) db_query("SELECT lid\n      FROM {locales_source}\n      WHERE textgroup = :textgroup\n      AND context = :context", array(
      ':textgroup' => $textgroup,
      ':context' => $context,
    ))
      ->fetchField();
  }

  /**
   * Get the {locales_source} lid value for a specific source.
   *
   * @param string $string
   *   The translation string to search for.
   * @param string $textgroup
   *   This string's textgroup; defaults to 'metatag'.
   *
   * @return int
   *   The {locales_source}.lid value for this string.
   */
  public function getTranslationLidBySource($string, $textgroup = 'metatag') {

    // Extra debug output.
    $this
      ->debugLocalesSourcesByContext('', $textgroup);

    // Look for the string that's actually being requested.
    return (int) db_query("SELECT lid\n      FROM {locales_source}\n      WHERE textgroup = :textgroup\n      AND source = :source", array(
      ':textgroup' => $textgroup,
      ':source' => $string,
    ))
      ->fetchField();
  }

  /**
   * Get the {locales_source} lid values for a specific context.
   *
   * @param string $context
   *   The context string to search for.
   * @param string $textgroup
   *   This string's textgroup; defaults to 'metatag'.
   *
   * @return int
   *   The {locales_source}.lid value for this string.
   */
  public function getTranslationsByContext($context, $textgroup = 'metatag') {
    return db_query("SELECT lid\n      FROM {locales_source}\n      WHERE textgroup = :textgroup\n      AND context = :context", array(
      ':textgroup' => $textgroup,
      ':context' => $context,
    ))
      ->fetchCol();
  }

  /**
   * Generate a dump of the {locales_source} records for a specific context.
   *
   * @param string $context
   *   The translation context to search against.
   * @param string $textgroup
   *   This string's textgroup; defaults to 'metatag'.
   */
  public function debugLocalesSourcesByContext($context, $textgroup = 'metatag') {

    // Get a dump of all i18n strings for Metatag.
    $records = db_query("SELECT lid, location, textgroup, source, context, version\n      FROM {locales_source}\n      WHERE textgroup = :textgroup", array(
      ':textgroup' => $textgroup,
    ))
      ->fetchAllAssoc('lid');
    foreach ($records as $key => $record) {
      $records[$key] = (array) $record;
    }
    $args = array(
      'caption' => 'i18n source check for . ' . $context,
      'header' => array(
        'lid',
        'location',
        'textgroup',
        'source',
        'context',
        'version',
      ),
      'rows' => $records,
    );
    $this
      ->verbose(theme('table', $args));
  }

  /**
   * Save a {locales_target} translation string to the database.
   *
   * @param int $lid
   *   The {locales_source}.lid primary key.
   * @param string $context
   *   The {locales_source}.context value for this string.
   * @param string $langcode
   *   The language the string is being translated into.
   * @param string $string_source
   *   The string that is being translated.
   * @param string $string_target
   *   The destination string.
   */
  public function saveTranslationString($lid, $context, $langcode, $string_source, $string_target) {

    // Load the translation page for the front page's title tag.
    $this
      ->drupalGet('admin/config/regional/translate/edit/' . $lid);
    $this
      ->assertResponse(200, 'Loaded the front page title tag string translation page.');
    $this
      ->assertEqual($this
      ->getUrl(), url('admin/config/regional/translate/edit/' . $lid, array(
      'absolute' => TRUE,
    )));

    // Confirm that the permission-check text is not found.
    $this
      ->assertNoText(t('This is a user-defined string. You are not allowed to translate these strings.'));

    // Look for the existing string. The string gets mungled by the Locale
    // module, so need to replicate its behaviour.
    $this
      ->assertText(check_plain(wordwrap($string_source, 0)));

    // Look for the context value; the context value is empty for all default
    // i.e. interface strings, so don't test this when the context is empty.
    if (!empty($context)) {
      $this
        ->assertText($context);
    }

    // Confirm that the destination strings exist.
    $source_locale = language_default('language');
    if (function_exists('i18n_string_source_language')) {
      $source_locale = i18n_string_source_language();
    }
    if ($source_locale != 'en') {
      $this
        ->assertField('translations[en]', 'Found the English translation string field.');
    }
    if ($source_locale != 'fr') {
      $this
        ->assertField('translations[fr]', 'Found the French translation string field.');
    }
    if ($source_locale != 'es') {
      $this
        ->assertField('translations[es]', 'Found the Spanish translation string field.');
    }

    // Translate the string.
    $edit = array(
      "translations[{$langcode}]" => $string_target,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save translations'));
    $this
      ->assertResponse(200);

    // Confirm the save worked.
    $this
      ->assertText(t('The string has been saved.'));
    $this
      ->assertEqual($this
      ->getUrl(), url('admin/config/regional/translate/translate', array(
      'absolute' => TRUE,
    )));

    // Debug output.
    $this
      ->debugLocalesTargetsByContext($context);

    // Clear the Metatag caches.
    metatag_flush_caches();
  }

  /**
   * Generate a dump of the {locales_target} records for a specific context.
   *
   * @param string $context
   *   The translation context to search against.
   */
  public function debugLocalesTargetsByContext($context) {

    // , lt.i18n_status
    $records = db_query("SELECT lt.lid, lt.translation, lt.language, lt.plid, lt.plural\n      FROM {locales_target} lt\n        INNER JOIN {locales_source} ls\n          ON lt.lid = ls.lid\n      WHERE ls.textgroup = 'metatag'\n        AND ls.context = :context", array(
      ':context' => $context,
    ))
      ->fetchAllAssoc('lid');
    foreach ($records as $key => $record) {
      $records[$key] = (array) $record;
    }
    $args = array(
      'caption' => 'Locale target check for . ' . $context,
      'header' => array(
        'lid',
        'translation',
        'language',
        'plid',
        'plural',
      ),
      'rows' => $records,
    );
    $this
      ->verbose(theme('table', $args));
  }

  /**
   * Creates an object which can be used for generating and checking behavior.
   *
   * @param string $identifier
   *   The machine name to identify this object in source code.
   * @param string $path
   *   Path where generate metatags.
   *
   * @return object
   *   A mapping object.
   */
  public function createTestObject($identifier, $path) {
    $test_object = new stdClass();
    $test_object->name = $identifier;
    $test_object->path = $path;
    $test_object->title = "My {$identifier} title";
    $test_object->description = "My {$identifier} description";
    $test_object->abstract = "My {$identifier} abstract";
    $test_object->keywords = "My {$identifier} keywords";
    return $test_object;
  }

  /**
   * Generates meta tags by path from a test_object.
   *
   * @param object $test_object
   *   Metatag mapping object.
   */
  public function generateByPathConfig($test_object) {

    // Verify the "add context" page works.
    $this
      ->drupalGet('admin/config/search/metatags/context');
    $this
      ->assertResponse(200);
    $this
      ->assertText(t('Add a meta tag by path'));

    // Verify the "add context" page works.
    $this
      ->drupalGet('admin/config/search/metatags/context/add');
    $this
      ->assertResponse(200);
    $this
      ->assertText(t('The unique ID for this metatag path context rule. This must contain only lower case letters, numbers and underscores.'));

    // Add new Metatag object for this configuration.
    $values = array(
      'name' => $test_object->name,
    );
    $this
      ->drupalPost('admin/config/search/metatags/context/add', $values, t('Add and configure'));
    $this
      ->assertResponse(200);
  }

  /**
   * Edits meta tags by path from a test_object.
   *
   * @param object $test_object
   *   Metatag mapping object.
   */
  public function editByPathConfig($test_object) {
    $edit = array(
      'paths' => $test_object->path,
      'metatags[und][title][value]' => $test_object->title,
      'metatags[und][description][value]' => $test_object->description,
      'metatags[und][abstract][value]' => $test_object->abstract,
      'metatags[und][keywords][value]' => $test_object->keywords,
    );
    $this
      ->drupalPost('admin/config/search/metatags/context/' . $test_object->name, $edit, t('Save'));
    $this
      ->assertResponse(200);
  }

  /**
   * Checks if meta tags have been added correctly from a test_object.
   *
   * @param object $test_object
   *   Metatag mapping object.
   */
  public function checkByPathConfig($test_object) {
    $this
      ->drupalGet($test_object->path);
    $this
      ->assertResponse(200);

    // Manually test the page title.
    if (!empty($test_object->title)) {
      $this
        ->assertTitle($test_object->title, 'Title found in ' . $test_object->path);
    }

    // Test the other meta tags.
    $tags = array(
      'description',
      'abstract',
      'keywords',
    );
    foreach ($tags as $tag) {
      if (!empty($test_object->{$tag})) {
        $this
          ->assertRaw($test_object->{$tag}, $tag . ' found in ' . $test_object->path);
      }
      else {
        $this
          ->assertNoRaw('<meta name="' . $tag, $tag . ' not found in ' . $test_object->path);
      }
    }
  }

  /**
   * Check the translation page for a specific string.
   *
   * @param string $string
   *   The source string to search for.
   * @param string $context
   *   The i18n string context to check for.
   * @param bool $assert_true
   *   By default strings are expeted to be found. If the string is not expected
   *   to be translatable yet then pass in FALSE.
   */
  public function searchTranslationPage($string, $context, $assert_true = TRUE) {

    // Load the translation page.
    $search = array(
      'string' => $string,
      'language' => 'all',
      'translation' => 'all',
      'group' => 'metatag',
    );
    $this
      ->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
    $this
      ->assertResponse(200, 'Loaded the translation admin page.');

    // Confirm there are strings to translate.
    $xpath = $this
      ->xpath("//body//div[@class='content']//table//tbody//tr");
    $count = count($xpath);

    // If the string is expected, then confirm that there are strings to be
    // found.
    if ($assert_true) {
      $this
        ->assertTrue($count >= 1, 'Found Metatag strings to translate.');
      $this
        ->assertNoText(t('No strings available.'));
      $xpath = $this
        ->xpath("//body//div[@class='content']//table//tbody//tr");
      $this
        ->verbose("Found {$count} items to translate.");
      if (!empty($string)) {
        $this
          ->assertText($context);
        $this
          ->assertText('metatag:' . $context);
      }
    }
    else {
      $this
        ->assertNoText($context);
      $this
        ->assertNoText('metatag:' . $context);
    }
  }

  /**
   * Create an image of a specific size & type.
   *
   * @param string $image_size
   *   The size of the requested image in 'XxY' format; defaults to '200x200'.
   * @param string $format
   *   The image format to use, defaults to 'png'.
   *
   * @return string
   *   The URL to a public file.
   */
  public function generateImage($image_size = '200x200', $format = 'png') {

    // Only proceed if the Devel Generate module is installed.
    if (module_exists('devel_generate')) {

      // Load the Devel Generate image generator logic.
      module_load_include('inc', 'devel_generate', 'image.devel_generate');
      $image_format = 'png';
      $image_size = '200x200';
      $temp_image = devel_generate_image($image_format, $image_size, $image_size);
      return file_unmanaged_move($temp_image, 'public://');
    }
    else {
      $this
        ->error('The Devel Generate module is not enabled, it must be added to the $modules array in the setUp() method for this test class.');
    }
  }

  /**
   * Create an image file object of a specific size & type.
   *
   * @param string $image_size
   *   The size of the requested image in 'XxY' format; defaults to '200x200'.
   * @param string $format
   *   The image format to use, defaults to 'png'.
   *
   * @return object
   *   The file object for the generated image.
   */
  public function generateImageFile($image_size = '200x200', $format = 'png') {

    // Generate a test image.
    $image_uri = $this
      ->generateImage();

    // Create a file object for this image.
    $file = new StdClass();
    $file->fid = NULL;
    $file->uid = 1;
    $file->uri = $image_uri;
    $file->filemime = file_get_mimetype($image_uri);
    $file->filesize = filesize($image_uri);
    $file->status = 1;
    $file->timestamp = filemtime($image_uri);
    $saved_file = file_save($file);
    return $saved_file;
  }

  /**
   * Verify a user entity's meta tags load correctly.
   *
   * @param object $user
   *   A user object that is to be tested.
   */
  protected function assertUserEntityTags($user) {

    // Load the user's profile page.
    $this
      ->drupalGet('user/' . $user->uid);
    $this
      ->assertResponse(200);

    // Verify the title is using the custom default for this vocabulary.
    $xpath = $this
      ->xpath("//meta[@name='abstract']");
    $this
      ->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.');
    $this
      ->assertEqual($xpath[0]['content'], $user->name . " ponies");
  }

  /**
   * Generate a string that is allowable as a machine name.
   *
   * @param int $length
   *   How long the machine name will be, defaults to eight characters.
   *
   * @return string
   *   A string that contains lowercase letters and numbers, with a letter as
   *   the first character.
   */
  public function randomMachineName($length = 8) {
    return strtolower($this
      ->randomName($length));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
MetatagTestBase::addSiteLanguage public function Add a locale to the site.
MetatagTestBase::assertUserEntityTags protected function Verify a user entity's meta tags load correctly.
MetatagTestBase::checkByPathConfig public function Checks if meta tags have been added correctly from a test_object.
MetatagTestBase::clearAllCaches public function Load the Performance admin page and clear all caches.
MetatagTestBase::createAdminUser public function Create an admin user for the tests.
MetatagTestBase::createContentType public function Create a content type for the tests.
MetatagTestBase::createTerm public function Returns a new taxonomy term in a specific vocabulary.
MetatagTestBase::createTestObject public function Creates an object which can be used for generating and checking behavior.
MetatagTestBase::createUser public function Create a normal user for the tests.
MetatagTestBase::createVocabulary public function Returns a new vocabulary with random properties.
MetatagTestBase::debugLocalesSourcesByContext public function Generate a dump of the {locales_source} records for a specific context.
MetatagTestBase::debugLocalesTargetsByContext public function Generate a dump of the {locales_target} records for a specific context.
MetatagTestBase::editByPathConfig public function Edits meta tags by path from a test_object.
MetatagTestBase::generateByPathConfig public function Generates meta tags by path from a test_object.
MetatagTestBase::generateImage public function Create an image of a specific size & type.
MetatagTestBase::generateImageFile public function Create an image file object of a specific size & type.
MetatagTestBase::getTestDefaults public function Return an list of default values.
MetatagTestBase::getTranslationLidByContext public function Get the {locales_source} lid value for a specific context.
MetatagTestBase::getTranslationLidBySource public function Get the {locales_source} lid value for a specific source.
MetatagTestBase::getTranslationsByContext public function Get the {locales_source} lid values for a specific context.
MetatagTestBase::randomMachineName public function Generate a string that is allowable as a machine name.
MetatagTestBase::saveTranslationString public function Save a {locales_target} translation string to the database.
MetatagTestBase::searchTranslationPage public function Check the translation page for a specific string.
MetatagTestBase::setUp public function Sets up a Drupal site for running functional and integration tests. Overrides DrupalWebTestCase::setUp 27
MetatagTestBase::setupLocales public function Set up a basic starting point for the locales.
MetatagTestBase::verbose protected function Logs a verbose message in a text file. Overrides DrupalTestCase::verbose