You are here

public function LinkFieldValidateTest::xTestLinkValidateSwitchingBetweenValidationStatus in Link 7

Validate switching between validation status.

Test if a bad url can sneak through un-filtered if we play with the validation...

@todo Enable this, fix any problems that come up.

File

tests/LinkFieldValidateTest.test, line 232
Link field Validation Tests.

Class

LinkFieldValidateTest
Link field Validation Tests.

Code

public function xTestLinkValidateSwitchingBetweenValidationStatus() {
  $this
    ->acquireContentTypes(1);
  $this->web_user = $this
    ->drupalCreateUser(array(
    'administer content types',
    'administer fields',
    'administer nodes',
    'access administration pages',
    'access content',
    'create ' . $this->content_types[0]->type . ' content',
    'edit any ' . $this->content_types[0]->type . ' content',
  ));
  $this
    ->drupalLogin($this->web_user);
  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,
    // <-- This is needed or we have an error.
    'attributes' => array(),
    'validate_url' => 0,
  );
  $field = $this
    ->createField($field_settings, 0);
  $this
    ->acquireNodes(2);
  $this
    ->drupalGet('node/' . $this->nodes[0]->nid);
  $edit = array();
  $title = $this
    ->randomName();
  $url = 'javascript:alert("http://example.com/' . $this
    ->randomName() . '")';
  $edit[$field['field_name'] . '[0][url]'] = $url;
  $edit[$field['field_name'] . '[0][title]'] = $title;
  $this
    ->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));

  // $this->pass($this->content);.
  // @codingStandardsIgnoreLine
  $this
    ->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
    // @codingStandardsIgnoreLine
    '%field' => $name,
    '%value' => trim($url),
  )));

  // Make sure we get a new version!
  $node = node_load($this->nodes[0]->nid, NULL, TRUE);
  $this
    ->assertEqual($url, $node->{$field['field_name']}[0]['url']);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertNoRaw($url, 'Make sure Javascript does not display.');

  // Turn the array validation back _on_.
  $edit = array(
    'validate_url' => TRUE,
  );
  $node_type_link = str_replace('_', '-', $node->type);

  // @codingStandardsIgnoreLine
  // $this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
  // $this->fail($this->content);.
  $this
    ->drupalPost('admin/content/node-type/' . $node_type_link . '/fields/' . $field['field_name'], $edit, t('Save field settings'));
  $this
    ->drupalGet('node/' . $node->nid);

  // This actually works because the display_url goes through the core
  // url() function.  But we should have a test that makes sure it continues
  // to work.
  $this
    ->assertNoRaw($url, 'Make sure Javascript does not display.');

  // $this->fail($this->content);.
}