Removing old tests and translations directories
This commit is contained in:
parent
433e7eec80
commit
dfa2e142a7
53 changed files with 0 additions and 20508 deletions
|
@ -1,764 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Basic simpletests to test options on link module.
|
||||
*/
|
||||
|
||||
// Let's include the parent class.
|
||||
module_load_include('test', 'content', 'tests/content.crud');
|
||||
|
||||
class LinkAttributeCrudTest extends ContentCrudTestCase {
|
||||
|
||||
private $zebra;
|
||||
|
||||
public $permissions = array(
|
||||
'access content',
|
||||
'administer content types',
|
||||
'administer nodes',
|
||||
'administer filters',
|
||||
'access comments',
|
||||
'post comments',
|
||||
'post comments without approval',
|
||||
'access administration pages',
|
||||
);
|
||||
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link Attribute Tests'),
|
||||
'description' => t('Tests the field attributes, making sure they appear in various displayed situations.'),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
$this->zebra = 0;
|
||||
parent::setUp('link');
|
||||
$this->loginWithPermissions($this->permissions);
|
||||
}
|
||||
|
||||
function createLink($url, $title, $attributes = array()) {
|
||||
return array(
|
||||
'url' => $url,
|
||||
'title' => $title,
|
||||
'attributes' => $attributes,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This usually isn't needed. $this->pass($this->content); will usually
|
||||
* display the current page.
|
||||
*/
|
||||
private function outputScreenContents($description, $basename) {
|
||||
// This is a hack to get a directory that won't be cleaned up by simpletest
|
||||
$file_dir = file_directory_path() .'/../simpletest_output_pages';
|
||||
if (!is_dir($file_dir)) {
|
||||
mkdir($file_dir, 0777, TRUE);
|
||||
}
|
||||
$output_path = "$file_dir/$basename." . $this->randomName(10) . '.html';
|
||||
$rv = file_put_contents($output_path, $this->drupalGetContent());
|
||||
$this->pass("$description: Contents of result page are ". l('here', $output_path));
|
||||
}
|
||||
|
||||
private function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
|
||||
$this->zebra++;
|
||||
$zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd';
|
||||
$cssFieldLocator = 'field-'. str_replace('_', '-', $field_name);
|
||||
$this->assertPattern('@<div class="field field-type-link '. $cssFieldLocator .'".*<div class="field-item '. $zebra_string .'">\s*'. $link_value .'\s*</div>@is',
|
||||
$message,
|
||||
$group);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure
|
||||
* that the node is being displayed.
|
||||
*/
|
||||
function testBasic() {
|
||||
$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.
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
$node->promote = 1; // We want this to show on front page for the teaser test.
|
||||
$node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
|
||||
node_save($node);
|
||||
|
||||
// Does this display on the node page?
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com'));
|
||||
|
||||
// Does this display on the front page?
|
||||
$this->drupalGet('<front>');
|
||||
// reset the zebra!
|
||||
$this->zebra = 0;
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com'));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test sees that we can create a link field with a defined class, and make sure
|
||||
* that class displays properly when the link is displayed.
|
||||
*/
|
||||
function testLinkWithClassOnField() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => 'test-class',
|
||||
'target' => 'default',
|
||||
'rel' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
$node->promote = 1; // We want this to show on front page for the teaser test.
|
||||
$node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
|
||||
node_save($node);
|
||||
|
||||
// Does this display on the node page?
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
//$this->outputScreenContents('Link field with class', 'link_');
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
|
||||
|
||||
// Does this display on the front page?
|
||||
$this->drupalGet('<front>');
|
||||
// reset the zebra!
|
||||
$this->zebra = 0;
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
|
||||
}
|
||||
|
||||
function testLinkWithNoFollowOnField() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
$node->promote = 1; // We want this to show on front page for the teaser test.
|
||||
$node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
|
||||
node_save($node);
|
||||
|
||||
// Does this display on the node page?
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
//$this->outputScreenContents('Link field with class', 'link_');
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('rel' => 'nofollow'))));
|
||||
|
||||
// Does this display on the front page?
|
||||
$this->drupalGet('<front>');
|
||||
// reset the zebra!
|
||||
$this->zebra = 0;
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('rel' => 'nofollow'))));
|
||||
}
|
||||
|
||||
function testLinkWithNoFollowOnFieldTargetNewWindow() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => LINK_TARGET_NEW_WINDOW,
|
||||
'rel' => 'nofollow',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
$node->promote = 1; // We want this to show on front page for the teaser test.
|
||||
$node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
|
||||
node_save($node);
|
||||
|
||||
// Does this display on the node page?
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
//$this->outputScreenContents('Link field with class', 'link_');
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('target' => '_blank', 'rel' => 'nofollow'))));
|
||||
//$this->pass($this->content);
|
||||
|
||||
// Does this display on the front page?
|
||||
$this->drupalGet('<front>');
|
||||
// reset the zebra!
|
||||
$this->zebra = 0;
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('target' => '_blank', 'rel' => 'nofollow'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying to reproduce exactly what's in issue #664990
|
||||
*
|
||||
* http://drupal.org/node/664990
|
||||
*/
|
||||
function testLinkWithNoFollowOnFieldTargetNewWindowAndAClass() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => 'testlink',
|
||||
'target' => LINK_TARGET_NEW_WINDOW,
|
||||
'rel' => 'nofollow',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
$node->promote = 1; // We want this to show on front page for the teaser test.
|
||||
$node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
|
||||
node_save($node);
|
||||
|
||||
// Does this display on the node page?
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
//$this->outputScreenContents('Link field with class', 'link_');
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'testlink', 'target' => '_blank', 'rel' => 'nofollow'))));
|
||||
//$this->pass($this->content);
|
||||
|
||||
// Does this display on the front page?
|
||||
$this->drupalGet('<front>');
|
||||
// reset the zebra!
|
||||
$this->zebra = 0;
|
||||
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'testlink', 'target' => '_blank', 'rel' => 'nofollow'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Another test for http://drupal.org/node/664990
|
||||
*/
|
||||
function test_Link_With_Title_Attribute_WithNoFollowOnFieldTargetNewWindowAndAClass_Form() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
'title' => '',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
$field_db_info = content_database_info($field);
|
||||
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
||||
|
||||
$edit = array();
|
||||
$edit['attributes[class]'] = 'testdata';
|
||||
$edit['attributes[target]'] = LINK_TARGET_NEW_WINDOW;
|
||||
$edit['attributes[rel]'] = 'nofollow';
|
||||
|
||||
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
|
||||
$edit, t('Save field settings'));
|
||||
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
|
||||
|
||||
// So, having saved this field_name, let's see if it works...
|
||||
$this->acquireNodes(1);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
|
||||
$title = 'title_'. $this->randomName(20);
|
||||
$edit[$field['field_name'] .'[0][title]'] = $title;
|
||||
|
||||
$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)));
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->assertText($title, 'Make sure the link title/text shows');
|
||||
//$this->assertRaw(' title="test_data"', "Do we show the title?");
|
||||
$this->assertLinkOnNode($field['field_name'],
|
||||
l($title,
|
||||
'http://www.example.com/test',
|
||||
array('attributes' => array('target' => '_blank',
|
||||
'rel' => 'nofollow',
|
||||
'class' => 'testdata'))));
|
||||
//$this->pass($this->content);
|
||||
}
|
||||
|
||||
function test_Link_With_Title_Attribute() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
'title' => 'test_title',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(1);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
|
||||
|
||||
$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)));
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->assertRaw(' title="test_title"', "Do we show the title?");
|
||||
//$this->assertRaw(l('http://www.example.com/test', 'http://www.example.com/test', array('attributes' => array('title' => 'test_title'))));
|
||||
}
|
||||
|
||||
function test_Link_With_Title_Attribute_form() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
'title' => '',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
$field_db_info = content_database_info($field);
|
||||
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
||||
|
||||
$edit = array('attributes[title]' => 'test_data');
|
||||
|
||||
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
|
||||
$edit, t('Save field settings'));
|
||||
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
|
||||
|
||||
// So, having saved this field_name, let's see if it works...
|
||||
$this->acquireNodes(1);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
|
||||
$title = 'title_'. $this->randomName(20);
|
||||
$edit[$field['field_name'] .'[0][title]'] = $title;
|
||||
|
||||
$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)));
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->assertText($title, 'Make sure the link title/text shows');
|
||||
$this->assertRaw(' title="test_data"', "Do we show the title?");
|
||||
}
|
||||
|
||||
/**
|
||||
* When the title attribute matches the link title, we need to suppress
|
||||
* the title attribute.
|
||||
*/
|
||||
function test_Link_With_Title_Attribute_Not_Shown_form() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
'title' => '',
|
||||
),
|
||||
);
|
||||
|
||||
$common_title = 'title_'. $this->randomName(20);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
$field_db_info = content_database_info($field);
|
||||
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
||||
|
||||
$edit = array('attributes[title]' => $common_title);
|
||||
|
||||
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
|
||||
$edit, t('Save field settings'));
|
||||
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
|
||||
|
||||
// So, having saved this field_name, let's see if it works...
|
||||
$this->acquireNodes(1);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
|
||||
$edit[$field['field_name'] .'[0][title]'] = $common_title;
|
||||
|
||||
$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)));
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->assertRaw('>'. $common_title .'<', 'Make sure the link title/text shows');
|
||||
$this->assertNoRaw(' title="'. $common_title .'"',
|
||||
"Do we hide the title, since it matches the link title?");
|
||||
//$this->pass($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* When the title attribute matches the link title, we need to suppress
|
||||
* the title attribute.
|
||||
*/
|
||||
function test_Link_without_title_attribute() {
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
'title' => '',
|
||||
),
|
||||
);
|
||||
|
||||
$common_title = 'title_'. $this->randomName(20);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
$field_db_info = content_database_info($field);
|
||||
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
||||
|
||||
// So, having saved this field_name, let's see if it works...
|
||||
$this->acquireNodes(1);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
|
||||
$edit[$field['field_name'] .'[0][title]'] = $common_title;
|
||||
|
||||
$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)));
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->assertRaw('>'. $common_title .'<', 'Make sure the link title/text shows');
|
||||
$this->assertNoRaw(' title=""',
|
||||
"Do we hide the title, since it is empty?");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This test exercises the bugfix for http://drupal.org/node/628902.
|
||||
* It's also making sure that if you set up a link field with 'rel="nofollow"'
|
||||
* and point it internally, then the link does not show rel="nofollow".
|
||||
*/
|
||||
function test_rel_nofollow_bug() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$field_name = 'field_'. $name;
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'value',
|
||||
'title_value' => $name,
|
||||
'attributes[rel]' => 'nofollow'), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'test', // internal link!
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
//$this->pass($this->content);
|
||||
$this->assertRaw(l($name, 'test'));//, array('attributes' => array('rel' => ''))));
|
||||
}
|
||||
|
||||
function test_rel_nofollow_on_external_link() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$field_name = 'field_'. $name;
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'value',
|
||||
'title_value' => $name,
|
||||
'attributes[rel]' => 'nofollow'), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName(), // internal link!
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
//$this->pass($this->content);
|
||||
$this->assertRaw(l($name, $input['href'], array('attributes' => array('rel' => 'nofollow'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Here we test the fix to #626932, where an empty or bad attributes value on the link at the field
|
||||
* level would cause the site to die in _link_sanitize, when the non-array $field['attributes'] is added
|
||||
* to another array.
|
||||
*/
|
||||
function test_bad_attributes_bugfix_null_global_settings() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$field_name = 'field_'. $name;
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'value',
|
||||
'title_value' => $name), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// ruin the stored data in content_node_field.
|
||||
// Here we replace the entire $field with a blank. The structure of the table
|
||||
// prevents it from being set to a null, sadly.
|
||||
db_query("UPDATE {content_node_field} SET global_settings = '' WHERE field_name = '%s'",
|
||||
$field_name);
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'test', // internal link!
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
//$this->pass($this->content);
|
||||
$this->assertRaw(l($name, 'test'));//, array('attributes' => array('rel' => ''))));
|
||||
}
|
||||
/**
|
||||
* Here we test the fix to #626932, where an empty or bad attributes value on the link at the field
|
||||
* level would cause the site to die in _link_sanitize, when the non-array $field['attributes'] is added
|
||||
* to another array.
|
||||
*/
|
||||
function test_bad_attributes_bugfix_string_attributes() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$field_name = 'field_'. $name;
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'value',
|
||||
'title_value' => $name), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// ruin the stored data in content_node_field.
|
||||
// Here we set $field['attributes'] equal to a string of length 0.
|
||||
db_query("UPDATE {content_node_field} SET global_settings = '%s' WHERE field_name = '%s'",
|
||||
'a:6:{s:10:"attributes";s:0:"";s:7:"display";a:1:{s:10:"url_cutoff";s:2:"80";}s:3:"url";i:0;s:5:"title";s:8:"optional";s:11:"title_value";s:0:"";s:13:"enable_tokens";i:1;}', $field_name);
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'test', // internal link!
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
//$this->pass($this->content);
|
||||
$this->assertRaw(l($name, 'test'));//, array('attributes' => array('rel' => ''))));
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure
|
||||
* that the node is being displayed.
|
||||
*/
|
||||
function testOptionalUrlStaticTitleDisplays() {
|
||||
$this->acquireContentTypes(1);
|
||||
variable_set('node_options_'. $this->content_types[0]->name, array('status', 'promote'));
|
||||
|
||||
$title_value = $this->randomName();
|
||||
$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.
|
||||
'url' => FALSE,
|
||||
'title' => 'value',
|
||||
'title_value' => $title_value,
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
$node->promote = 1; // We want this to show on front page for the teaser test.
|
||||
$node->{$field['field_name']}[0] = $this->createLink('', '');
|
||||
node_save($node);
|
||||
|
||||
// Does this display on the node page?
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
//$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com'));
|
||||
$this->assertNoRaw($title_value, 'Title value should not be displayed for a blank field if the title is static.');
|
||||
|
||||
// Does this display on the front page?
|
||||
$this->drupalGet('<front>');
|
||||
// reset the zebra!
|
||||
$this->zebra = 0;
|
||||
//$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com'));
|
||||
$this->assertNoRaw($title_value, 'Title value should not be displayed for a blank field if the title is static.');
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Basic CRUD simpletests for the link module, based off of content.crud.test in CCK.
|
||||
*/
|
||||
|
||||
// Need to include content.crud.test so we can inherit from it's ContentCrudTestCase.
|
||||
require_once(drupal_get_path('module', 'content') .'/tests/content.crud.test');
|
||||
|
||||
class LinkContentCrudTest extends ContentCrudTestCase {
|
||||
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link CRUD - Basic API tests'),
|
||||
'description' => t('Tests the field CRUD (create, read, update, delete) API. <strong>Requires <a href="@schema_link">Schema module</a>.</strong>', array('@schema_link' => 'http://www.drupal.org/project/schema')),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('link');
|
||||
$this->loginWithPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* All we're doing here is creating a content type, creating a simple link field
|
||||
* on that content type, and making sure said field exists in the database.
|
||||
*/
|
||||
function testLinkCreateFieldAPI() {
|
||||
$this->acquireContentTypes(1);
|
||||
|
||||
$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
|
||||
|
||||
//$this->pass(print_r($this->content_types, TRUE));
|
||||
//$this->pass(print_r($field, TRUE));
|
||||
|
||||
$table_schema = drupal_get_schema();
|
||||
//$this->pass(print_r(array_keys($table_schema), TRUE));
|
||||
// Check the schema - the values should be in the per-type table.
|
||||
$this->assertSchemaMatchesTables(array(
|
||||
'per_type' => array(
|
||||
$this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,340 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Testing CRUD API in the browser.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Testing that users can not input bad URLs or labels
|
||||
*/
|
||||
class LinkUITest extends DrupalWebTestcase {
|
||||
|
||||
/**
|
||||
* Link supposed to be good
|
||||
*/
|
||||
const LINK_INPUT_TYPE_GOOD = 0;
|
||||
|
||||
/**
|
||||
* Link supposed to have a bad title
|
||||
*/
|
||||
const LINK_INPUT_TYPE_BAD_TITLE = 1;
|
||||
|
||||
/**
|
||||
* Link supposed to have a bad URL
|
||||
*/
|
||||
const LINK_INPUT_TYPE_BAD_URL = 2;
|
||||
|
||||
/**
|
||||
* Implementation of getInfo().
|
||||
*/
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link CRUD - browser test'),
|
||||
'description' => t('Tests the field CRUD (create, read, update, delete) API.'),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of setUp().
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp('content', 'link');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link field for the "page" type and creates a page with a link.
|
||||
*/
|
||||
function testLinkCreate() {
|
||||
//libxml_use_internal_errors(true);
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array('validate_url' => TRUE), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input_test_cases = array(
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
'msg' => 'Link found',
|
||||
'type' => self::LINK_INPUT_TYPE_GOOD
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '<script>alert("hi");</script>',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '<script src="http://devil.site.com"></script>',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '" onmouseover="alert(\'hi\')',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
|
||||
'label' => $this->randomName(),
|
||||
'msg' => 'js url',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_URL
|
||||
),
|
||||
);
|
||||
foreach ($input_test_cases as $input) {
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'],
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
|
||||
$this->assertRaw(t('Not a valid URL.'), 'Not a valid URL: ' . $input['href']);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Page', '%title' => $edit['title'])), 'Page created: ' . $input['href']);
|
||||
}
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonym user
|
||||
$this->drupalLogout();
|
||||
|
||||
$this->drupalGet($url);
|
||||
//debug($this);
|
||||
// If simpletest starts using something to override the error system, this will flag
|
||||
// us and let us know it's broken.
|
||||
$this->assertFalse(libxml_use_internal_errors(TRUE));
|
||||
$path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]';
|
||||
//$this->pass(htmlentities($path));
|
||||
$elements = $this->xpath($path);
|
||||
libxml_use_internal_errors(FALSE);
|
||||
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
|
||||
}
|
||||
//libxml_use_internal_errors(FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link field for the "page" type and creates a page with a link.
|
||||
* Just like the above test, only here we're turning off the validation on the field.
|
||||
*/
|
||||
function testLinkCreate_NoValidation() {
|
||||
//libxml_use_internal_errors(true);
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array('validate_url' => FALSE), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
_content_type_info(TRUE);
|
||||
$fields = content_fields();
|
||||
$this->assertTRUE(0 === $fields['field_'. $name]['validate_url'], 'Make sure validation is off.');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input_test_cases = array(
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
'msg' => 'Link found',
|
||||
'type' => self::LINK_INPUT_TYPE_GOOD
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '<script>alert("hi");</script>',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '<script src="http://devil.site.com"></script>',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '" onmouseover="alert(\'hi\')',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')',
|
||||
'msg' => 'js label',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
|
||||
),
|
||||
array(
|
||||
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
|
||||
'label' => $this->randomName(),
|
||||
'msg' => 'js url',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_URL
|
||||
),
|
||||
);
|
||||
foreach ($input_test_cases as $input) {
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'],
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
|
||||
//$this->assertRaw(t('Not a valid URL.'), 'Not a valid URL: ' . $input['href']);
|
||||
$this->assertNoRaw($input['href']);
|
||||
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Page', '%title' => $edit['title'])), 'Page created: ' . $input['href']);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Page', '%title' => $edit['title'])), 'Page created: ' . $input['href']);
|
||||
}
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonym user
|
||||
$this->drupalLogout();
|
||||
|
||||
$this->drupalGet($url);
|
||||
//debug($this);
|
||||
// If simpletest starts using something to override the error system, this will flag
|
||||
// us and let us know it's broken.
|
||||
$this->assertFalse(libxml_use_internal_errors(TRUE));
|
||||
$path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]';
|
||||
//$this->pass(htmlentities($path));
|
||||
$elements = $this->xpath($path);
|
||||
libxml_use_internal_errors(FALSE);
|
||||
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
|
||||
}
|
||||
//libxml_use_internal_errors(FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing that if you use <strong> in a static title for your link, that the
|
||||
* title actually displays <strong>.
|
||||
*/
|
||||
function testStaticLinkCreate() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$field_name = 'field_'. $name;
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'value',
|
||||
'title_value' => '<strong>'. $name .'</strong>'), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName()
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l('<strong>'. $name .'</strong>', $input['href'], array('html' => TRUE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* If we're creating a new field and just hit 'save' on the default options, we want to make
|
||||
* sure they are set to the expected results.
|
||||
*/
|
||||
function testCRUDCreateFieldDefaults() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
_content_type_info(TRUE);
|
||||
$fields = content_fields();
|
||||
$field = $fields['field_'. $name];
|
||||
$this->assertTrue(1 === $field['validate_url'], 'Make sure validation is on.');
|
||||
$this->assertFalse($field['required'], 'Make sure field is not required.');
|
||||
$this->assertEqual($field['title'], 'optional', 'Title should be optional by default.');
|
||||
$this->assertFalse($field['enable_tokens'], 'Enable Tokens should be off by default.');
|
||||
$this->assertEqual($field['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
|
||||
$this->assertEqual($field['attributes']['target'], 'default', 'Target should be "default"');
|
||||
$this->assertFalse($field['attributes']['rel'], 'Rel should be blank by default.');
|
||||
$this->assertFalse($field['attributes']['class'], 'By default, no class should be set.');
|
||||
$this->assertFalse($field['attributes']['title'], 'By default, no title should be set.');
|
||||
|
||||
//$this->fail('<pre>'. print_r($fields['field_'. $name], TRUE) .'</pre>');
|
||||
}
|
||||
}
|
|
@ -1,531 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains simpletests making sure token integration works.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Testing that tokens can be used in link titles
|
||||
*/
|
||||
class LinkTokenTest 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',
|
||||
);
|
||||
|
||||
/**
|
||||
* Implementation of getInfo().
|
||||
*/
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link tokens - browser test'),
|
||||
'description' => t('Tests including tokens in link titles, making sure they appear in node views. <strong>Requires <a href="@token_link">Token module</a>.</strong>'),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of setUp().
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp('content', 'link', 'token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link field with a required title enabled for user-entered tokens.
|
||||
* Creates a node with a token in the link title and checks the value.
|
||||
*/
|
||||
function testUserTokenLinkCreate() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'required',
|
||||
'enable_tokens' => TRUE), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
);
|
||||
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'] . " [type]",
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l($input['label'] . ' page', $input['href']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a link field with a static title and an admin-entered token.
|
||||
* Creates a node with a link and checks the title value.
|
||||
*/
|
||||
function testStaticTokenLinkCreate() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'value',
|
||||
'title_value' => $name . ' [type]',
|
||||
'enable_tokens' => FALSE,
|
||||
), t('Save field settings'));
|
||||
|
||||
// Is filed created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName()
|
||||
);
|
||||
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l($name . ' page', $input['href']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link field with a static title and an admin-entered token.
|
||||
* Creates a node with a link and checks the title value.
|
||||
*
|
||||
* Basically, I want to make sure the [title-raw] token works, because it's a
|
||||
* token that changes from node to node, where [type]'s always going to be the
|
||||
* same.
|
||||
*/
|
||||
function testStaticTokenLinkCreate2() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'value',
|
||||
'title_value' => $name . ' [title-raw]',
|
||||
'enable_tokens' => FALSE,
|
||||
), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName()
|
||||
);
|
||||
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l($name .' '. $name, $input['href']));
|
||||
}
|
||||
|
||||
function test_Link_With_Title_Attribute_token_url_form() {
|
||||
$this->loginWithPermissions($this->permissions);
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
'title' => '',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_name = $field['field_name'];
|
||||
$field_db_info = content_database_info($field);
|
||||
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
||||
|
||||
$edit = array('attributes[title]' => '['. $field_name .'-url]',
|
||||
'enable_tokens' => FALSE);
|
||||
|
||||
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
|
||||
$edit, t('Save field settings'));
|
||||
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
|
||||
|
||||
// So, having saved this field_name, let's see if it works...
|
||||
$this->acquireNodes(1);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$test_link_url = 'http://www.example.com/test';
|
||||
$edit[$field['field_name'] .'[0][url]'] = $test_link_url;
|
||||
$title = 'title_'. $this->randomName(20);
|
||||
$edit[$field['field_name'] .'[0][title]'] = $title;
|
||||
|
||||
$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)));
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->assertText($title, 'Make sure the link title/text shows');
|
||||
$this->assertRaw(' title="'. $test_link_url .'"', "Do we show the link url as the title attribute?");
|
||||
$this->assertNoRaw(' title="['. $field_name .'-url]"');
|
||||
$this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
|
||||
//$this->fail($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the title of the link is set to the title attribute, then the title
|
||||
* attribute isn't supposed to show.
|
||||
*/
|
||||
function test_Link_With_Title_Attribute_token_title_form() {
|
||||
$this->loginWithPermissions($this->permissions);
|
||||
$this->acquireContentTypes(1);
|
||||
$field_settings = array(
|
||||
'type' => 'link',
|
||||
'widget_type' => 'link',
|
||||
'type_name' => $this->content_types[0]->name,
|
||||
'attributes' => array(
|
||||
'class' => '',
|
||||
'target' => 'default',
|
||||
'rel' => 'nofollow',
|
||||
'title' => '',
|
||||
),
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
$field_name = $field['field_name'];
|
||||
$field_db_info = content_database_info($field);
|
||||
$url_type = str_replace('_', '-', $this->content_types[0]->type);
|
||||
|
||||
$edit = array('attributes[title]' => '['. $field_name .'-title]',
|
||||
'enable_tokens' => FALSE);
|
||||
|
||||
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
|
||||
$edit, t('Save field settings'));
|
||||
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
|
||||
|
||||
// So, having saved this field_name, let's see if it works...
|
||||
$this->acquireNodes(1);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
|
||||
$title = 'title_'. $this->randomName(20);
|
||||
$edit[$field['field_name'] .'[0][title]'] = $title;
|
||||
|
||||
$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)));
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->assertText($title, 'Make sure the link title/text shows');
|
||||
$this->assertNoRaw(' title="'. $title .'"', "We should not show the link title as the title attribute?");
|
||||
$this->assertNoRaw(' title="['. $field_name .'-title]"');
|
||||
//$this->fail($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying to set the url to contain a token.
|
||||
*/
|
||||
function testUserTokenLinkCreateInURL() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'required',
|
||||
'enable_tokens' => TRUE), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
);
|
||||
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'],
|
||||
$field_name . '[0][url]' => $input['href'] . "/[type]",
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l($input['label'], $input['href'] .'/page'));
|
||||
//$this->fail($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* If 'enable_tokens' is off, then the url shouldn't be filtered through the token module.
|
||||
*/
|
||||
function testUserTokenLinkCreateInURLFail() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'required',
|
||||
'enable_tokens' => FALSE), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
);
|
||||
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'],
|
||||
$field_name . '[0][url]' => $input['href'] . "/[type]",
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l($input['label'], $input['href'] .'/[type]'));
|
||||
//$this->fail($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying to set the url to contain a token.
|
||||
*/
|
||||
function testUserTokenLinkCreateInURL2() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'required',
|
||||
'enable_tokens' => TRUE), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
);
|
||||
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'],
|
||||
$field_name . '[0][url]' => $input['href'] . "/[author-uid]",
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l($input['label'], $input['href'] .'/'. $account->uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link field with a required title enabled for user-entered tokens.
|
||||
* Creates a node with a token in the link title and checks the value.
|
||||
*/
|
||||
function testHostTokenLinkCreate() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'_add_new_field[label]' => $name,
|
||||
'_add_new_field[field_name]' => $name,
|
||||
'_add_new_field[type]' => 'link',
|
||||
'_add_new_field[widget_type]' => 'link',
|
||||
);
|
||||
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'title' => 'required',
|
||||
'enable_tokens' => TRUE), t('Save field settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
|
||||
|
||||
// create page form
|
||||
$this->drupalGet('node/add/page');
|
||||
$field_name = 'field_' . $name;
|
||||
$this->assertField($field_name . '[0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
);
|
||||
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'] . " [$field_name-host]",
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw(l($input['label'] . ' example.com', $input['href']));
|
||||
}
|
||||
}
|
|
@ -1,497 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests that exercise the validation functions in the link module.
|
||||
*/
|
||||
|
||||
// Let's include the parent class.
|
||||
module_load_include('test', 'content', 'tests/content.crud');
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
||||
class LinkValidateTest extends LinkValidateTestCase {
|
||||
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link Validation Tests'),
|
||||
'description' => t('Tests the field validation.'),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
function test_link_validate_basic_url() {
|
||||
$this->link_test_validate_url('http://www.example.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we're stopped from posting a bad url on default validation.
|
||||
*/
|
||||
function test_link_validate_bad_url_validate_default() {
|
||||
$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->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'edik:naw';
|
||||
|
||||
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
|
||||
//$this->pass($this->content);
|
||||
$this->assertText(t('Not a valid URL.'));
|
||||
|
||||
// Make sure we get a new version!
|
||||
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
|
||||
$this->assertNotEqual('edik:naw', $node->{$field['field_name']}[0]['url']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we're stopped from posting a bad url with validation on.
|
||||
*/
|
||||
function test_link_validate_bad_url_validate_on() {
|
||||
$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->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'edik:naw';
|
||||
|
||||
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
|
||||
//$this->pass($this->content);
|
||||
$this->assertText(t('Not a valid URL.'));
|
||||
|
||||
// Make sure we get a new version!
|
||||
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
|
||||
$this->assertNotEqual('edik:naw', $node->{$field['field_name']}[0]['url']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can post a bad url if the validation is expressly turned off.
|
||||
*/
|
||||
function test_link_validate_bad_url_validate_off() {
|
||||
$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' => 0,
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$this->drupalGet('node/'. $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'edik:naw';
|
||||
|
||||
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
|
||||
//$this->pass($this->content);
|
||||
$this->assertNoText(t('Not a valid URL.'));
|
||||
|
||||
// Make sure we get a new version!
|
||||
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
|
||||
$this->assertEqual('edik:naw', $node->{$field['field_name']}[0]['url']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a bad url can sneak through un-filtered if we play with the validation...
|
||||
*/
|
||||
function test_link_validate_switching_between_validation_status() {
|
||||
$this->acquireContentTypes(1);
|
||||
$account = $this->drupalCreateUser(array('administer content types',
|
||||
'administer nodes',
|
||||
'access administration pages',
|
||||
'access content',
|
||||
'create '. $this->content_types[0]->type .' content',
|
||||
'edit any '. $this->content_types[0]->type .' content'));
|
||||
$this->drupalLogin($account);
|
||||
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' => 0,
|
||||
);
|
||||
|
||||
$field = $this->createField($field_settings, 0);
|
||||
//$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
|
||||
$field_db_info = content_database_info($field);
|
||||
|
||||
$this->acquireNodes(2);
|
||||
|
||||
$node = node_load($this->nodes[0]->nid);
|
||||
|
||||
$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);
|
||||
$this->assertNoText(t('Not a valid 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);
|
||||
//$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);
|
||||
|
||||
}
|
||||
|
||||
// Validate that '<front>' is a valid url.
|
||||
function test_link_front_url() {
|
||||
$this->link_test_validate_url('<front>');
|
||||
}
|
||||
|
||||
// Validate that an internal url would be accepted.
|
||||
function test_link_internal_url() {
|
||||
$this->link_test_validate_url('node/32');
|
||||
}
|
||||
|
||||
// Validate a simple mailto.
|
||||
function test_link_mailto() {
|
||||
$this->link_test_validate_url('mailto:jcfiala@gmail.com');
|
||||
}
|
||||
|
||||
function test_link_external_https() {
|
||||
$this->link_test_validate_url('https://www.example.com/');
|
||||
}
|
||||
|
||||
function test_link_ftp() {
|
||||
$this->link_test_validate_url('ftp://www.example.com/');
|
||||
}
|
||||
}
|
||||
|
||||
class LinkValidateTestNews extends LinkValidateTestCase {
|
||||
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link News Validation Tests'),
|
||||
'description' => t('Tests the field validation for usenet urls.'),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
// Validate a news link to a message group
|
||||
function test_link_news() {
|
||||
$this->link_test_validate_url('news:comp.infosystems.www.misc');
|
||||
}
|
||||
|
||||
// Validate a news link to a message id. Said ID copied off of google groups.
|
||||
function test_link_news_message() {
|
||||
$this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
|
||||
}
|
||||
}
|
||||
|
||||
class LinkValidateSpecificURL extends LinkValidateTestCase {
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link Specific URL Validation Tests'),
|
||||
'description' => t('Tests field validation with unusual urls'),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
// Lets throw in a lot of umlouts for testing!
|
||||
function test_umlout_url() {
|
||||
$this->link_test_validate_url('http://üÜü.exämple.com/nöde');
|
||||
}
|
||||
|
||||
function test_umlout_mailto() {
|
||||
$this->link_test_validate_url('mailto:Üser@exÅmple.com');
|
||||
}
|
||||
|
||||
function test_german_b_url() {
|
||||
$this->link_test_validate_url('http://www.test.com/ßstuff');
|
||||
}
|
||||
|
||||
function test_special_n_url() {
|
||||
$this->link_test_validate_url('http://www.testÑñ.com/');
|
||||
}
|
||||
|
||||
function test_curly_brackets_in_query() {
|
||||
$this->link_test_validate_url('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}');
|
||||
}
|
||||
|
||||
/**
|
||||
* Here, we're testing that a very long url is stored properly in the db.
|
||||
*
|
||||
* Basicly, trying to test http://drupal.org/node/376818
|
||||
*/
|
||||
function testLinkURLFieldIsBig() {
|
||||
$long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A';
|
||||
$this->link_test_validate_url($long_url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A series of tests of links, only going against the link_validate_url function in link.module.
|
||||
*
|
||||
* Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 !
|
||||
*/
|
||||
class LinkValidateUrlLight extends DrupalUnitTestCase {
|
||||
|
||||
function setUp() {
|
||||
// do we need to include something here?
|
||||
module_load_include('module', 'link');
|
||||
module_load_include('inc', 'link');
|
||||
}
|
||||
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Link Light Validation Tests'),
|
||||
'description' => t('Tests the link_validate_url() function by itself, without invoking the full drupal/cck lifecycle.'),
|
||||
'group' => t('Link'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the LINK type constants to english for display and debugging of tests
|
||||
*/
|
||||
function name_Link_Type($type) {
|
||||
switch ($type) {
|
||||
case LINK_FRONT:
|
||||
return "Front";
|
||||
case LINK_EMAIL:
|
||||
return "Email";
|
||||
case LINK_NEWS:
|
||||
return "Newsgroup";
|
||||
case LINK_INTERNAL:
|
||||
return "Internal Link";
|
||||
case LINK_EXTERNAL:
|
||||
return "External Link";
|
||||
case FALSE:
|
||||
return "Invalid Link";
|
||||
default:
|
||||
return "Bad Value:". $type;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that a link labelled <front> works.
|
||||
function testValidateFrontLink() {
|
||||
$valid = link_validate_url('<front>');
|
||||
$this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verfied and identified');
|
||||
}
|
||||
|
||||
function testValidateEmailLink() {
|
||||
$valid = link_validate_url('mailto:bob@example.com');
|
||||
$this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified");
|
||||
}
|
||||
|
||||
function testValidateEmailLinkBad() {
|
||||
$valid = link_validate_url(':bob@example.com');
|
||||
$this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
|
||||
}
|
||||
|
||||
function testValidateNewsgroupLink() {
|
||||
$valid = link_validate_url('news:comp.infosystems.www.misc');
|
||||
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.');
|
||||
}
|
||||
|
||||
function testValidateNewsArticleLink() {
|
||||
$valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
|
||||
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article valiates as news.');
|
||||
}
|
||||
|
||||
function testValidateBadNewsgroupLink() {
|
||||
$valid = link_validate_url('news:comp.bad_name.misc');
|
||||
$this->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.');
|
||||
}
|
||||
|
||||
function testValidateInternalLink() {
|
||||
$valid = link_validate_url('node/5');
|
||||
$this->assertEqual(LINK_INTERNAL, $valid, 'Test normal internal link.');
|
||||
}
|
||||
|
||||
function testValidateInternalLinkWithDot() {
|
||||
$valid = link_validate_url('rss.xml');
|
||||
$this->assertEqual(LINK_INTERNAL, $valid, 'Test rss.xml internal link.');
|
||||
}
|
||||
|
||||
function testValidateInternalLinkToFile() {
|
||||
$valid = link_validate_url('files/test.jpg');
|
||||
$this->assertEqual(LINK_INTERNAL, $valid, 'Test files/test.jpg internal link.');
|
||||
}
|
||||
|
||||
function testValidateExternalLinks() {
|
||||
$links = array(
|
||||
'http://localhost:8080/',
|
||||
'www.example.com',
|
||||
'www.example.com/',
|
||||
'http://username:p%40ssw0rd!@www.example.com/',
|
||||
'http://@www.example.com/',
|
||||
'http://username:@www.example.com/',
|
||||
'http://username:password@www.example.com:8080/',
|
||||
'http://127.0.0.1:80/',
|
||||
'http://127.173.24.255:4723/',
|
||||
'127.173.24.255:4723/',
|
||||
'http://255.255.255.255:4823/',
|
||||
'www.test-site.com',
|
||||
'http://example.com/index.php?q=node/123',
|
||||
'http://example.com/index.php?page=this\that',
|
||||
'http://example.com/?first_name=Joe Bob&last_name=Smith',
|
||||
// Anchors
|
||||
'http://www.example.com/index.php#test',
|
||||
'http://www.example.com/index.php#this@that.',
|
||||
'http://www.example.com/index.php#',
|
||||
'http://www.cnn.com/video/#/video/politics/2008/12/09/intv.madeleine.albright.cnn',
|
||||
'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up',
|
||||
'http://www.example.com/blah/#this@that?',
|
||||
);
|
||||
// Test all of the protocols.
|
||||
$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
|
||||
foreach ($allowed_protocols as $protocol) {
|
||||
if ($protocol !== 'news' && $protocol !== 'mailto') {
|
||||
$links[] = $protocol .'://www.example.com';
|
||||
}
|
||||
}
|
||||
foreach ($links as $link) {
|
||||
$valid = link_validate_url($link);
|
||||
$this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that '. $link .' is a valid external link.');
|
||||
}
|
||||
}
|
||||
|
||||
function testInvalidExternalLinks() {
|
||||
$links = array(
|
||||
'http://www.ex ample.com/',
|
||||
'//www.example.com/',
|
||||
'http://25.0.0/', // bad ip!
|
||||
'http://4827.0.0.2/',
|
||||
'http://www.testß.com/', // ß not allowed in domain names!
|
||||
//'http://www.-fudge.com/', // domains can't have sections starting with a dash.
|
||||
);
|
||||
foreach ($links as $link) {
|
||||
$valid = link_validate_url($link);
|
||||
$this->assertEqual(FALSE, $valid, 'Testing that '. $link .' is not a valid link.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue