Commit dbbda1d0 authored by John C Fiala's avatar John C Fiala
Browse files

bug report #1008562 by jcfiala:Looking into URL, as link error caused me to...

bug report #1008562 by jcfiala:Looking into URL, as link error caused me to realize that the _link_sanitize was being called in the wrong place - now called on link_field_prepare_view.
parent 6587e544
...@@ -212,11 +212,21 @@ function link_field_validate($entity_type, $entity, $field, $instance, $langcode ...@@ -212,11 +212,21 @@ function link_field_validate($entity_type, $entity, $field, $instance, $langcode
*/ */
function link_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { function link_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as $delta => $value) { foreach ($items as $delta => $value) {
_link_sanitize($items[$delta], $delta, $field, $instance, $entity);
_link_process($items[$delta], $delta, $field, $entity); _link_process($items[$delta], $delta, $field, $entity);
} }
} }
/**
* Implements hook_field_prepare_view().
*/
function link_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
foreach ($items as $entity_id => $entity_items) {
foreach ($entity_items as $delta => $value) {
_link_sanitize($items[$entity_id][$delta], $delta, $field, $instances[$entity_id], $entities[$entity_id]);
}
}
}
/** /**
* Implements hook_field_widget_info(). * Implements hook_field_widget_info().
*/ */
......
<?php
/**
* @file
* Link base test file - contains common functions for testing links.
*/
class LinkBaseTestClass extends DrupalWebTestCase {
public $permissions = array(
'access content',
'administer content types',
'administer nodes',
'administer filters',
'access comments',
'post comments',
'access administration pages',
'create page content',
);
public $account;
function setUp($modules = array()) {
if ($modules) {
parent::setUp($modules);
}
else {
parent::setUp('field_ui', 'link');
}
$this->account = $this->drupalCreateUser($this->permissions);
$this->drupalLogin($this->account);
}
function createLinkField($node_type = 'page',
$settings = array()) {
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$field_name = 'field_'. $name;
$this->drupalPost('admin/structure/types/manage/'. $node_type .'/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, $settings, t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
return $field_name;
}
}
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Contains simpletests making sure token integration works.
*/
// Let's include the parent class.
module_load_include('inc', 'link', 'tests/link.base-test');
/**
* Testing that tokens can be used in link titles
*/
class LinkTokenTest extends LinkBaseTestClass {
/**
* 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(array('field_ui', '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
$settings = array(
'instance[settings][enable_tokens]' => 1,
);
$field_name = $this->createLinkField('page',
$settings);
// create page form
$this->drupalGet('node/add/page');
//$field_name = 'field_' . $name;
$this->assertField($field_name . '[und][0][title]', 'Title found');
$this->assertField($field_name . '[und][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 . '[und][0][title]' => $input['label'] . " [node:content-type:machine-name]",
$field_name . '[und][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() {
// create field
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name .' [node:content-type:machine-name]');
$field_name = $this->createLinkField('page', $settings);
// create page form
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][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 . '[und][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() {
// create field
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name .' [node:title]');
$field_name = $this->createLinkField('page', $settings);
// create page form
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][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 . '[und][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']));
}
// This test doesn't seem to actually work, due to lack of 'title' in url.
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' => TRUE);
$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'])));*/
$name = $this->randomName();
$settings = array(
'instance[settings][attributes][rel]' => 'nofollow',
);
$field_name = $this->createLinkField('page', $settings);
// 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_name .'[und][0][url]'] = $test_link_url;
$title = 'title_'. $this->randomName(20);
$edit[$field_name .'[und][0][title]'] = $title;
$edit['title'] = $name;
$this->drupalGet('node/add/page');
$this->drupalPost(NULL, $edit, t('Save'));
// Make sure we get a new version!
//$node = node_load($this->nodes[0]->nid, NULL, TRUE);
$this->assertText(t('Basic page @title has been updated.',
array('@title' => $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' => TRUE);
$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' => 1), 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);
}
/**
* 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' => 1), 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));
}
}
...@@ -7,25 +7,12 @@ ...@@ -7,25 +7,12 @@
*/ */
// Let's include the parent class. // Let's include the parent class.
module_load_include('test', 'content', 'tests/content.crud'); module_load_include('inc', 'link', 'tests/link.base-test');
class LinkValidateTestCase extends DrupalWebTestcase { class LinkValidateTestCase extends LinkBaseTestClass {
public $permissions = array(
'access content',
'administer content types',
'administer nodes',
'administer filters',
'access comments',
'post comments',
'access administration pages',
'create page content',
);
function setUp() { function setUp() {
parent::setUp('field_ui', 'link'); parent::setUp();
//$this->loginWithPermissions($this->permissions);
$account = $this->drupalCreateUser($this->permissions);
$this->drupalLogin($account);
} }
function createLink($url, $title, $attributes = array()) { function createLink($url, $title, $attributes = array()) {
...@@ -39,50 +26,9 @@ class LinkValidateTestCase extends DrupalWebTestcase { ...@@ -39,50 +26,9 @@ class LinkValidateTestCase extends DrupalWebTestcase {
/** /**
* Takes a url, and sees if it can validate that the url is valid. * Takes a url, and sees if it can validate that the url is valid.
*/ */
function link_test_validate_url($url) { public 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); $field_name = $this->createLinkField();
$edit = array();
$edit[$field['field_name'] .'[0][url]'] = $url;
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));*/
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$field_name = 'field_'. $name;
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array(), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
$permission = 'create page content'; $permission = 'create page content';
$this->checkPermissions(array($permission), TRUE); $this->checkPermissions(array($permission), TRUE);
...@@ -97,11 +43,8 @@ class LinkValidateTestCase extends DrupalWebTestcase { ...@@ -97,11 +43,8 @@ class LinkValidateTestCase extends DrupalWebTestcase {
); );
$this->drupalPost(NULL, $edit, t('Save')); $this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t(' has been created.'), 'Node created'); $this->assertRaw(t(' has been created.'), 'Node created');
//$url = $this->getUrl();
//$this->assert('debug', $url, 'Debug');
//preg_match('/\/(\d*)/', $url, $matches);
$nid = 1; //$matches[1]; $nid = 1; //$matches[1];
//$this->assert('debug', print_r($matches, TRUE), 'Debug');
$node = node_load($nid); $node = node_load($nid);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment