Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
link
Commits
7170806a
Commit
7170806a
authored
Oct 15, 2014
by
John Fiala
Browse files
Issue #0 by jcfiala: Various small fixes to pass coder review.
parent
cfc3e7d3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
127 additions
and
118 deletions
+127
-118
link.module
link.module
+33
-23
tests/link.attribute.test
tests/link.attribute.test
+29
-29
tests/link.crud.test
tests/link.crud.test
+2
-2
tests/link.crud_browser.test
tests/link.crud_browser.test
+13
-14
tests/link.test
tests/link.test
+2
-2
tests/link.token.test
tests/link.token.test
+21
-21
tests/link.validate.test
tests/link.validate.test
+24
-24
views/link_views_handler_argument_target.inc
views/link_views_handler_argument_target.inc
+1
-1
views/link_views_handler_filter_protocol.inc
views/link_views_handler_filter_protocol.inc
+2
-2
No files found.
link.module
View file @
7170806a
...
...
@@ -133,14 +133,14 @@ function link_field_instance_settings_form($field, $instance) {
);
if
(
module_exists
(
'token'
))
{
// Add token module replacements fields
// Add token module replacements fields
.
$form
[
'enable_tokens'
]
=
array
(
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Allow user-entered tokens'
),
'#default_value'
=>
isset
(
$instance
[
'settings'
][
'enable_tokens'
])
?
$instance
[
'settings'
][
'enable_tokens'
]
:
1
,
'#description'
=>
t
(
'Checking will allow users to enter tokens in URLs and Titles on the entity edit form. This does not affect the field settings on this page.'
),
);
$entity_info
=
entity_get_info
(
$instance
[
'entity_type'
]);
$form
[
'tokens_help'
]
=
array
(
'#theme'
=>
'token_tree'
,
...
...
@@ -372,7 +372,7 @@ function _link_load($field, $item, $instance) {
/**
* Prepares the item attributes and url for storage.
*/
function
_link_process
(
&
$item
,
$delta
=
0
,
$field
,
$entity
)
{
function
_link_process
(
&
$item
,
$delta
,
$field
,
$entity
)
{
// Trim whitespace from URL.
if
(
!
empty
(
$item
[
'url'
]))
{
$item
[
'url'
]
=
trim
(
$item
[
'url'
]);
...
...
@@ -431,10 +431,11 @@ function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &
);
}
// In a totally bizzaro case, where URLs and titles are optional but the field is required, ensure there is at least one link.
if
(
$instance
[
'settings'
][
'url'
]
===
'optional'
&&
$instance
[
'settings'
][
'title'
]
===
'optional'
&&
(
strlen
(
trim
(
$item
[
'url'
]))
!==
0
||
strlen
(
trim
(
$item
[
'title'
]))
!==
0
))
{
if
(
$instance
[
'settings'
][
'url'
]
===
'optional'
&&
$instance
[
'settings'
][
'title'
]
===
'optional'
&&
(
strlen
(
trim
(
$item
[
'url'
]))
!==
0
||
strlen
(
trim
(
$item
[
'title'
]))
!==
0
))
{
$optional_field_found
=
TRUE
;
}
// Require entire field
// Require entire field
.
if
(
$instance
[
'settings'
][
'url'
]
===
'optional'
&&
$instance
[
'settings'
][
'title'
]
===
'optional'
&&
$instance
[
'required'
]
==
1
&&
!
$optional_field_found
&&
isset
(
$instance
[
'id'
]))
{
$errors
[
$field
[
'field_name'
]][
$langcode
][
$delta
][]
=
array
(
'error'
=>
'link_required'
,
...
...
@@ -447,13 +448,13 @@ function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &
/**
* Clean up user-entered values for a link field according to field settings.
*
* @param $item
* @param
array
$item
* A single link item, usually containing url, title, and attributes.
* @param $delta
* @param
int
$delta
* The delta value if this field is one of multiple fields.
* @param $field
* @param
array
$field
* The CCK field definition.
* @param $entity
* @param
object
$entity
* The entity containing this link.
*/
function
_link_sanitize
(
&
$item
,
$delta
,
&
$field
,
$instance
,
&
$entity
)
{
...
...
@@ -560,7 +561,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
// Unserialize attributtes array if it has not been unserialized yet.
if
(
!
is_array
(
$item
[
'attributes'
]))
{
$item
[
'attributes'
]
=
(
array
)
unserialize
(
$item
[
'attributes'
]);
$item
[
'attributes'
]
=
(
array
)
unserialize
(
$item
[
'attributes'
]);
}
// Add default attributes.
...
...
@@ -609,8 +610,8 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$item
[
'attributes'
][
'title'
]
=
token_replace
(
$item
[
'attributes'
][
'title'
],
array
(
$entity_token_type
=>
$entity_loaded
));
$item
[
'attributes'
][
'title'
]
=
filter_xss
(
$item
[
'attributes'
][
'title'
],
array
(
'b'
,
'br'
,
'code'
,
'em'
,
'i'
,
'img'
,
'span'
,
'strong'
,
'sub'
,
'sup'
,
'tt'
,
'u'
));
}
// Handle classes
if
(
!
empty
(
$item
[
'attributes'
][
'class'
])){
// Handle
attribute
classes
.
if
(
!
empty
(
$item
[
'attributes'
][
'class'
]))
{
$classes
=
explode
(
' '
,
$item
[
'attributes'
][
'class'
]);
foreach
(
$classes
as
&
$class
)
{
$class
=
drupal_html_class
(
$class
);
...
...
@@ -635,7 +636,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
* @param string $url
* URL to parse.
*
* @return
A
rray
* @return
a
rray
* Array of url pieces - only 'url', 'query', and 'fragment'.
*/
function
_link_parse_url
(
$url
)
{
...
...
@@ -656,7 +657,9 @@ function _link_parse_url($url) {
}
/**
* Bacause parse_str replaces the following characters in query parameters name
* Replaces the PHP parse_str() function.
*
* Because parse_str replaces the following characters in query parameters name
* in order to maintain compability with deprecated register_globals directive:
*
* - chr(32) ( ) (space)
...
...
@@ -667,7 +670,7 @@ function _link_parse_url($url) {
* @param string $query
* Query to parse.
*
* @return
A
rray
* @return
a
rray
* Array of query parameters.
*
* @see http://php.net/manual/en/language.variables.external.php#81080
...
...
@@ -751,7 +754,7 @@ function theme_link_field($vars) {
$output
.
=
'<div class="link-attributes">'
.
drupal_render
(
$element
[
'attributes'
][
'title'
])
.
'</div>'
;
}
if
(
!
empty
(
$element
[
'attributes'
][
'class'
]))
{
$output
.
=
'<div class="link-attributes">'
.
drupal_render
(
$element
[
'attributes'
][
'class'
])
.
'</div>'
;
$output
.
=
'<div class="link-attributes">'
.
drupal_render
(
$element
[
'attributes'
][
'class'
])
.
'</div>'
;
}
$output
.
=
drupal_render_children
(
$element
);
return
$output
;
...
...
@@ -1013,7 +1016,7 @@ function theme_link_formatter_link_plain($vars) {
}
/**
* Formats a link as an absolute URL
* Formats a link as an absolute URL
.
*/
function
theme_link_formatter_link_absolute
(
$vars
)
{
$absolute
=
array
(
'absolute'
=>
TRUE
);
...
...
@@ -1082,10 +1085,8 @@ function theme_link_formatter_link_separate($vars) {
unset
(
$link_options
[
'url'
]);
$title
=
empty
(
$vars
[
'element'
][
'title'
])
?
''
:
check_plain
(
$vars
[
'element'
][
'title'
]);
/**
* @TODO static html markup looks not very elegant
* needs smarter output solution and an optional title/url seperator
*/
// @TODO static html markup looks not very elegant
// needs smarter output solution and an optional title/url seperator
$url_parts
=
_link_parse_url
(
$vars
[
'element'
][
'url'
]);
$output
=
''
;
$output
.
=
'<div class="link-item '
.
$class
.
'">'
;
...
...
@@ -1099,6 +1100,8 @@ function theme_link_formatter_link_separate($vars) {
/**
* Implements hook_token_list().
*
* @TODO: hook_token_list no longer exists - this should change to hook_token_info().
*/
function
link_token_list
(
$type
=
'all'
)
{
if
(
$type
===
'field'
||
$type
===
'all'
)
{
...
...
@@ -1110,6 +1113,11 @@ function link_token_list($type = 'all') {
}
}
/**
* Implements hook_token_values().
*
* @TODO: hook_token_values no longer exists - this should change to hook_tokens().
*/
function
link_token_values
(
$type
,
$object
=
NULL
)
{
if
(
$type
===
'field'
)
{
$item
=
$object
[
0
];
...
...
@@ -1139,6 +1147,7 @@ function link_views_api() {
* protocol specified
*
* @param string $url
* The url entered by the user.
* @param string $protocol
* The protocol to be prepended to the url if one is not specified
*/
...
...
@@ -1169,6 +1178,7 @@ function link_cleanup_url($url, $protocol = 'http') {
* addresses following the RFC 2368 standard for mailto address formation.
*
* @param string $text
* Url to be validated.
*
* @return mixed
* Returns boolean FALSE if the URL is not valid. On success, returns one of
...
...
@@ -1238,7 +1248,7 @@ function link_validate_url($text) {
$allowed_protocols
=
variable_get
(
'filter_allowed_protocols'
,
array
(
'http'
,
'https'
,
'ftp'
,
'news'
,
'nntp'
,
'telnet'
,
'mailto'
,
'irc'
,
'ssh'
,
'sftp'
,
'webcal'
));
$LINK_DOMAINS
=
_link_domains
();
// Starting a parenthesis group with (?: means that it is grouped, but is not captured
// Starting a parenthesis group with (?: means that it is grouped, but is not captured
.
$protocol
=
'((?:'
.
implode
(
"|"
,
$allowed_protocols
)
.
'):\/\/)'
;
$authentication
=
"(?:(?:(?:[\w\.\-\+!$&'\(\)*\+,;="
.
$LINK_ICHARS
.
"]|%[0-9a-f]
{
2
}
)+(?::(?:[\w"
.
$LINK_ICHARS
.
"\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]
{
2
}
)*)?)?@)"
;
$domain
=
'(?:(?:[a-z0-9'
.
$LINK_ICHARS_DOMAIN
.
']([a-z0-9'
.
$LINK_ICHARS_DOMAIN
.
'\-_\[\]])*)(\.(([a-z0-9'
.
$LINK_ICHARS_DOMAIN
.
'\-_\[\]])+\.)*('
.
$LINK_DOMAINS
.
'|[a-z]{2}))?)'
;
...
...
@@ -1348,7 +1358,7 @@ function link_field_settings_form() {
/**
* Additional callback to adapt the property info of link fields.
*
* @see entity_metadata_field_entity_property_info()
.
* @see entity_metadata_field_entity_property_info()
*/
function
link_field_property_info_callback
(
&
$info
,
$entity_type
,
$field
,
$instance
,
$field_type
)
{
$property
=
&
$info
[
$entity_type
][
'bundles'
][
$instance
[
'bundle'
]][
'properties'
][
$field
[
'field_name'
]];
...
...
tests/link.attribute.test
View file @
7170806a
...
...
@@ -46,8 +46,8 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
protected
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'
,
$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
);
}
...
...
@@ -66,7 +66,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// Create the content type.
$this
->
clickLink
(
t
(
'Add content type'
));
$edit
=
array
(
$edit
=
array
(
'name'
=>
$content_type_friendly
,
'type'
=>
$content_type_machine
,
);
...
...
@@ -76,8 +76,8 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// Now add a singleton field.
$single_field_name_friendly
=
$this
->
randomName
(
20
);
$single_field_name_machine
=
strtolower
(
$this
->
randomName
(
10
));
$single_field_name
=
'field_'
.
$single_field_name_machine
;
$edit
=
array
(
$single_field_name
=
'field_'
.
$single_field_name_machine
;
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$single_field_name_friendly
,
'fields[_add_new_field][field_name]'
=>
$single_field_name_machine
,
'fields[_add_new_field][type]'
=>
'link_field'
,
...
...
@@ -112,19 +112,19 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this
->
drupalLogin
(
$this
->
web_user
);
// Go to page.
$this
->
drupalGet
(
'node/add/'
.
$content_type_machine
);
$this
->
drupalGet
(
'node/add/'
.
$content_type_machine
);
// Add a node.
$edit
=
array
(
'title'
=>
$title
,
'field_'
.
$single_field_name_machine
.
'[und][0][title]'
=>
'Link'
,
'field_'
.
$single_field_name_machine
.
'[und][0][url]'
=>
'http://www.drupal.org/'
,
'field_'
.
$single_field_name_machine
.
'[und][0][title]'
=>
'Link'
,
'field_'
.
$single_field_name_machine
.
'[und][0][url]'
=>
'http://www.drupal.org/'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
$this
->
assertText
(
t
(
'@content_type_friendly @title has been created'
,
array
(
'@content_type_friendly'
=>
$content_type_friendly
,
'@title'
=>
$title
)));
$this
->
drupalGet
(
'node/add/'
.
$content_type_machine
);
$this
->
drupalGet
(
'node/add/'
.
$content_type_machine
);
// Create a node:
$edit
=
array
(
...
...
@@ -143,7 +143,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
protected
function
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
)
{
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/fields'
);
$edit
=
array
(
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$single_field_name_friendly
,
'fields[_add_new_field][field_name]'
=>
$single_field_name_machine
,
'fields[_add_new_field][type]'
=>
'link_field'
,
...
...
@@ -180,7 +180,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
}
protected
function
createNodeForTesting
(
$content_type_machine
,
$content_type_friendly
,
$single_field_name_machine
,
$title
,
$url
,
$node_title
=
''
)
{
$this
->
drupalGet
(
'node/add/'
.
$content_type_machine
);
$this
->
drupalGet
(
'node/add/'
.
$content_type_machine
);
if
(
!
$node_title
)
{
$node_title
=
$this
->
randomName
(
20
);
...
...
@@ -219,10 +219,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this
->
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
);
// Okay, now we want to make sure this display is changed:
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$edit
=
array
(
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_plain'
,
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_plain'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
@@ -270,10 +270,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this
->
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
);
// Okay, now we want to make sure this display is changed:
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$edit
=
array
(
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_url'
,
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_url'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
@@ -320,10 +320,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this
->
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
);
// Okay, now we want to make sure this display is changed:
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$edit
=
array
(
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_short'
,
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_short'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
@@ -371,10 +371,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this
->
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
);
// Okay, now we want to make sure this display is changed:
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$edit
=
array
(
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_label'
,
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_label'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
@@ -422,10 +422,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this
->
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
);
// Okay, now we want to make sure this display is changed:
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$edit
=
array
(
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_separate'
,
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_separate'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
@@ -474,10 +474,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this
->
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
);
// Okay, now we want to make sure this display is changed:
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$edit
=
array
(
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_title_plain'
,
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_title_plain'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
tests/link.crud.test
View file @
7170806a
...
...
@@ -37,7 +37,7 @@ class LinkContentCrudTest extends DrupalWebTestCase {
// Create the content type.
$this
->
clickLink
(
t
(
'Add content type'
));
$edit
=
array
(
$edit
=
array
(
'name'
=>
$content_type_friendly
,
'type'
=>
$content_type_machine
,
);
...
...
@@ -47,7 +47,7 @@ class LinkContentCrudTest extends DrupalWebTestCase {
// Now add a singleton field.
$single_field_name_friendly
=
$this
->
randomName
(
20
);
$single_field_name_machine
=
strtolower
(
$this
->
randomName
(
10
));
$edit
=
array
(
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$single_field_name_friendly
,
'fields[_add_new_field][field_name]'
=>
$single_field_name_machine
,
'fields[_add_new_field][type]'
=>
'link_field'
,
...
...
tests/link.crud_browser.test
View file @
7170806a
...
...
@@ -76,8 +76,8 @@ class LinkUITest extends DrupalWebTestcase {
//$this->drupalGet('node/add');
$this
->
drupalGet
(
'node/add/page'
);
$field_name
=
'field_'
.
$name
;
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-title'
,
'Title found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-url'
,
'URL found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-title'
,
'Title found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-url'
,
'URL found'
);
$input_test_cases
=
array
(
array
(
...
...
@@ -124,12 +124,12 @@ class LinkUITest extends DrupalWebTestcase {
),
);
$test_case
=
array
(
'href'
=>
'www.example.com/'
.
$this
->
randomName
(),
'href'
=>
'www.example.com/'
.
$this
->
randomName
(),
'label'
=>
$this
->
randomName
(),
'msg'
=>
'Link found'
,
'type'
=>
self
::
LINK_INPUT_TYPE_GOOD
,
);
$test_case
[
'expected_href'
]
=
'http://'
.
$test_case
[
'href'
];
$test_case
[
'expected_href'
]
=
'http://'
.
$test_case
[
'href'
];
$input_test_cases
[]
=
$test_case
;
foreach
(
$input_test_cases
as
$input
)
{
...
...
@@ -147,13 +147,13 @@ class LinkUITest extends DrupalWebTestcase {
continue
;
}
else
{
$this
->
assertRaw
(
t
(
'
has been created.'
,
$this
->
assertRaw
(
' '
.
t
(
'has been created.'
,
array
(
'@type'
=>
'Basic Page'
,
'%title'
=>
$edit
[
'title'
])),
'Page created: '
.
$input
[
'href'
]);
}
$url
=
$this
->
getUrl
();
// change to
a
nonym user
// change to
A
nonym
ous
user
.
$this
->
drupalLogout
();
$this
->
drupalGet
(
$url
);
...
...
@@ -162,12 +162,11 @@ class LinkUITest extends DrupalWebTestcase {
// us and let us know it's broken.
$this
->
assertFalse
(
libxml_use_internal_errors
(
TRUE
));
if
(
isset
(
$input
[
'expected_href'
]))
{
$path
=
'//a[@href="'
.
$input
[
'expected_href'
]
.
'" and text()="'
.
$input
[
'label'
]
.
'"]'
;
$path
=
'//a[@href="'
.
$input
[
'expected_href'
]
.
'" and text()="'
.
$input
[
'label'
]
.
'"]'
;
}
else
{
$path
=
'//a[@href="'
.
$input
[
'href'
]
.
'" and text()="'
.
$input
[
'label'
]
.
'"]'
;
$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'
]);
...
...
@@ -185,7 +184,7 @@ class LinkUITest extends DrupalWebTestcase {
// create field
$name
=
strtolower
(
$this
->
randomName
());
$field_name
=
'field_'
.
$name
;
$field_name
=
'field_'
.
$name
;
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$name
,
'fields[_add_new_field][field_name]'
=>
$name
,
...
...
@@ -196,7 +195,7 @@ class LinkUITest extends DrupalWebTestcase {
$this
->
drupalPost
(
NULL
,
array
(),
t
(
'Save field settings'
));
$this
->
drupalPost
(
NULL
,
array
(
'instance[settings][title]'
=>
'value'
,
'instance[settings][title_value]'
=>
'<strong>'
.
$name
.
'</strong>'
),
t
(
'Save settings'
));
'instance[settings][title_value]'
=>
'<strong>'
.
$name
.
'</strong>'
),
t
(
'Save settings'
));
// Is field created?
$this
->
assertRaw
(
t
(
'Saved %label configuration'
,
array
(
'%label'
=>
$name
)),
'Field added'
);
...
...
@@ -221,7 +220,7 @@ class LinkUITest extends DrupalWebTestcase {
$this
->
drupalLogout
();
$this
->
drupalGet
(
$url
);
$this
->
assertRaw
(
l
(
'<strong>'
.
$name
.
'</strong>'
,
$input
[
'href'
],
array
(
'html'
=>
TRUE
)));
$this
->
assertRaw
(
l
(
'<strong>'
.
$name
.
'</strong>'
,
$input
[
'href'
],
array
(
'html'
=>
TRUE
)));
}
/**
...
...
@@ -233,7 +232,7 @@ class LinkUITest extends DrupalWebTestcase {
// create field
$name
=
strtolower
(
$this
->
randomName
());
$field_name
=
'field_'
.
$name
;
$field_name
=
'field_'
.
$name
;
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$name
,
'fields[_add_new_field][field_name]'
=>
$name
,
...
...
@@ -302,7 +301,7 @@ class LinkUITest extends DrupalWebTestcase {
_field_info_collate_fields
(
TRUE
);
$instances
=
field_info_instances
(
'node'
,
'page'
);
$instance
=
$instances
[
'field_'
.
$name
];
$instance
=
$instances
[
'field_'
.
$name
];
$this
->
assertFalse
(
$instance
[
'required'
],
'Make sure field is not required.'
);
$this
->
assertEqual
(
$instance
[
'settings'
][
'title'
],
'optional'
,
'Title should be optional by default.'
);
$this
->
assertTrue
(
$instance
[
'settings'
][
'validate_url'
],
'Make sure validation is on.'
);
...
...
tests/link.test
View file @
7170806a
...
...
@@ -36,8 +36,8 @@ class LinkBaseTestClass extends DrupalWebTestCase {
'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'
));
$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'
));
...
...
tests/link.token.test
View file @
7170806a
...
...
@@ -75,7 +75,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$name
=
$this
->
randomName
();
$settings
=
array
(
'instance[settings][title]'
=>
'value'
,
'instance[settings][title_value]'
=>
$name
.
' [node:content-type:machine-name]'
);
'instance[settings][title_value]'
=>
$name
.
' [node:content-type:machine-name]'
);
$field_name
=
$this
->
createLinkField
(
'page'
,
$settings
);
// create page form
...
...
@@ -118,7 +118,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$name
=
$this
->
randomName
();
$settings
=
array
(
'instance[settings][title]'
=>
'value'
,
'instance[settings][title_value]'
=>
$name
.
' [node:title]'
);
'instance[settings][title_value]'
=>
$name
.
' [node:title]'
);
$field_name
=
$this
->
createLinkField
(
'page'
,
$settings
);
// create page form
...
...
@@ -144,7 +144,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$this
->
drupalLogout
();
$this
->
drupalGet
(
$url
);
$this
->
assertRaw
(
l
(
$name
.
' '
.
$name
,
$input
[
'href'
]));
$this
->
assertRaw
(
l
(
$name
.
' '
.
$name
,
$input
[
'href'
]));
}
// This test doesn't seem to actually work, due to lack of 'title' in url.
...
...
@@ -191,9 +191,9 @@ class LinkTokenTest extends LinkBaseTestClass {
$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
[
$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'
);
...
...
@@ -206,8 +206,8 @@ class LinkTokenTest extends LinkBaseTestClass {
//$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
->
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);
}
...
...
@@ -236,10 +236,10 @@ class LinkTokenTest extends LinkBaseTestClass {
$field_db_info
=
content_database_info
(
$field
);
$url_type
=
str_replace
(
'_'
,
'-'
,
$this
->
content_types
[
0
]
->
type
);
$edit
=
array
(
'attributes[title]'
=>
'['
.
$field_name
.
'-title]'
,
$edit
=
array
(
'attributes[title]'
=>
'['
.
$field_name
.
'-title]'
,
'enable_tokens'
=>
TRUE
);
$this
->
drupalPost
(
'admin/content/node-type/'
.
$url_type
.
'/fields/'
.
$field
[
'field_name'
],
$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'
])));
...
...
@@ -248,14 +248,14 @@ class LinkTokenTest extends LinkBaseTestClass {
$node
=
node_load
(
$this
->
nodes
[
0
]
->
nid
);
$this
->
drupalGet
(
'node/'
.
$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
;
$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'
));
$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
);
...
...
@@ -263,10 +263,10 @@ class LinkTokenTest extends LinkBaseTestClass {
array
(
'@title'
=>
$node
->
title
,
'@type'
=>
$this
->
content_types
[
0
]
->
name
)));
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$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
->
assertNoRaw
(
' title="'
.
$title
.
'"'
,
"We should not show the link title as the title attribute?"
);
$this
->
assertNoRaw
(
' title="['
.
$field_name
.
'-title]"'
);
//$this->fail($this->content);
}
...
...
@@ -319,7 +319,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$this
->
drupalLogout
();
$this
->
drupalGet
(
$url
);
$this
->
assertRaw
(
l
(
$input
[
'label'
],
$input
[
'href'
]
.
'/page'
));
$this
->
assertRaw
(
l
(
$input
[
'label'
],
$input
[
'href'
]
.
'/page'
));
//$this->fail($this->content);
}
...
...
@@ -372,7 +372,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$this
->
drupalLogout
();
$this
->
drupalGet
(
$url
);
$this
->
assertRaw
(
l
(
$input
[
'label'
],
$input
[
'href'
]
.
'/'
.
$this
->
web_user
->
uid
));
$this
->
assertRaw
(
l
(
$input
[
'label'
],
$input
[
'href'
]
.
'/'
.
$this
->
web_user
->
uid
));
}
/**
...
...
@@ -385,7 +385,7 @@ class LinkTokenTest extends LinkBaseTestClass {
// create field
$name
=
strtolower
(
$this
->
randomName
());
$field_name
=
'field_'
.
$name
;
$field_name
=
'field_'
.
$name
;
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$name
,
'fields[_add_new_field][field_name]'
=>
$name
,
...
...
tests/link.validate.test
View file @
7170806a
...
...
@@ -34,7 +34,7 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$field_name
.
'[und][0][url]'
=>
$url
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
$this
->
assertRaw
(
t
(
' has been created.'
)
,
'Node created'
);
$this
->
assertRaw
(
' has been created.'
,
'Node created'
);
$nid
=
1
;
//$matches[1];
...
...
@@ -90,13 +90,13 @@ class LinkValidateTest extends LinkValidateTestCase {
// create page form
$this
->
drupalGet
(
'node/add/page'
);
$field_name
=
'field_'
.
$name
;
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-title'
,
'Title found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-url'
,
'URL found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-title'
,
'Title found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-url'
,
'URL found'
);
$edit
=
array
(
'title'
=>
'Simple Title'
,
$field_name
.
'[und][0][url]'
=>
'edik:naw'
,
$field_name
.
'[und][0][url]'
=>
'edik:naw'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
@@ -135,13 +135,13 @@ class LinkValidateTest extends LinkValidateTestCase {
// create page form
$this
->
drupalGet
(
'node/add/page'
);
$field_name
=
'field_'
.
$name
;
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-title'
,
'Title found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-url'
,
'URL found'
);
$this
->
assertField
(
'edit-field-'
.
$name
.
'-und-0-title'
,
'Title found'
);