You are here

class LinkValidateTestCase in Link 6.2

Hierarchy

Expanded class hierarchy of LinkValidateTestCase

File

tests/link.validate.test, line 11
Tests that exercise the validation functions in the link module.

View source
class LinkValidateTestCase extends ContentCrudTestCase {
  public $permissions = array(
    'access content',
    'administer content types',
    'administer nodes',
    'administer filters',
    'access comments',
    'post comments',
    'post comments without approval',
    'access administration pages',
  );
  function setUp() {
    parent::setUp('link');
    $this
      ->loginWithPermissions($this->permissions);
  }
  function createLink($url, $title, $attributes = array()) {
    return array(
      'url' => $url,
      'title' => $title,
      'attributes' => $attributes,
    );
  }

  /**
   * Takes a url, and sees if it can validate that the url is valid.
   */
  function link_test_validate_url($url) {
    $this
      ->acquireContentTypes(1);
    variable_set('node_options_' . $this->content_types[0]->name, array(
      'status',
      'promote',
    ));
    $field_settings = array(
      'type' => 'link',
      'widget_type' => 'link',
      'type_name' => $this->content_types[0]->name,
      'attributes' => array(),
      // <-- This is needed or we have an error.
      'validate_url' => 1,
    );
    $field = $this
      ->createField($field_settings, 0);

    //$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
    $field_db_info = content_database_info($field);
    $this
      ->acquireNodes(1);

    //$this->fail("We now have ". count($this->nodes) ." nodes.");
    $node = node_load($this->nodes[0]->nid);
    $this
      ->drupalGet('node/' . $this->nodes[0]->nid);
    $edit = array();
    $edit[$field['field_name'] . '[0][url]'] = $url;
    $this
      ->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));

    // Make sure we get a new version!
    $node = node_load($this->nodes[0]->nid, NULL, TRUE);
    $this
      ->assertText(t('@type @title has been updated.', array(
      '@title' => $node->title,
      '@type' => $this->content_types[0]->name,
    )), t('Testing %url', array(
      '%url' => $url,
    )));
    $this
      ->assertEqual($url, $node->{$field['field_name']}[0]['url']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkValidateTestCase::$permissions public property
LinkValidateTestCase::createLink function
LinkValidateTestCase::link_test_validate_url function Takes a url, and sees if it can validate that the url is valid.
LinkValidateTestCase::setUp function