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
2e82084e
Commit
2e82084e
authored
Nov 03, 2014
by
John Fiala
Browse files
Issue #2367069 by jcfiala:Fixed entity_token for link after node_view was called.
parent
729ceac2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
5 deletions
+70
-5
link.module
link.module
+3
-3
tests/link.entity_token.test
tests/link.entity_token.test
+67
-2
No files found.
link.module
View file @
2e82084e
...
...
@@ -496,12 +496,12 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$url_parts
=
_link_parse_url
(
$url
);
if
(
!
empty
(
$url_parts
[
'url'
]))
{
$item
[
'url'
]
=
$url_parts
[
'url'
];
$item
+=
array
(
'query'
=>
isset
(
$url_parts
[
'query'
])
?
$url_parts
[
'query'
]
:
NULL
,
$item
[
'url'
]
=
url
(
$url_parts
[
'url'
],
array
(
'query'
=>
isset
(
$url_parts
[
'query'
])
?
$url_parts
[
'query'
]
:
NULL
,
'fragment'
=>
isset
(
$url_parts
[
'fragment'
])
?
$url_parts
[
'fragment'
]
:
NULL
,
'absolute'
=>
!
empty
(
$instance
[
'settings'
][
'absolute_url'
]),
'html'
=>
TRUE
,
)
);
}
...
...
tests/link.entity_token.test
View file @
2e82084e
...
...
@@ -24,9 +24,9 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
}
/**
* Creates a link field, fills it,
and
then
attempts to use the url value in a
token.
* Creates a link field, fills it, then
uses a loaded node to test
token
s
.
*/
function
testFieldToken
()
{
function
testFieldToken
NodeLoaded
()
{
// create field
$settings
=
array
(
'instance[settings][enable_tokens]'
=>
0
,
...
...
@@ -87,4 +87,69 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
}
}
/**
* Creates a link field, fills it, then uses a loaded and node_view'd node to test tokens.
*/
function
testFieldTokenNodeViewed
()
{
// create field
$settings
=
array
(
'instance[settings][enable_tokens]'
=>
0
,
);
$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'
);
$token_url_tests
=
array
(
1
=>
array
(
'href'
=>
'http://example.com/'
.
$this
->
randomName
(),
'label'
=>
$this
->
randomName
(),
),
2
=>
array
(
'href'
=>
'http://example.com/'
.
$this
->
randomName
()
.
'?property=value'
,
'label'
=>
$this
->
randomName
(),
),
3
=>
array
(
'href'
=>
'http://example.com/'
.
$this
->
randomName
()
.
'#position'
,
'label'
=>
$this
->
randomName
(),
),
4
=>
array
(
'href'
=>
'http://example.com/'
.
$this
->
randomName
()
.
'#lower?property=value2'
,
'label'
=>
$this
->
randomName
(),
),
);
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');
foreach
(
$token_url_tests
as
&
$input
)
{
$this
->
drupalGet
(
'node/add/page'
);
$edit
=
array
(
'title'
=>
$input
[
'label'
],
$field_name
.
'[und][0][title]'
=>
$input
[
'label'
],
$field_name
.
'[und][0][url]'
=>
$input
[
'href'
],
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
$url
=
$this
->
getUrl
();
$input
[
'url'
]
=
$url
;
}
// change to anonymous user
$this
->
drupalLogout
();
foreach
(
$token_url_tests
as
$index
=>
$input2
)
{
$node
=
node_load
(
$index
);
$node_array
=
node_view
(
$node
,
'full'
);
$this
->
assertNotEqual
(
NULL
,
$node
,
"Do we have a node?"
);
$this
->
assertEqual
(
$node
->
nid
,
$index
,
"Test that we have a node."
);
$token_name
=
'[node:'
.
str_replace
(
'_'
,
'-'
,
$field_name
)
.
':url]'
;
$assert_data
=
token_replace
(
$token_name
,
array
(
'node'
=>
$node
));
$this
->
assertEqual
(
$input2
[
'href'
],
$assert_data
,
"Test that the url token has been set to "
.
$input2
[
'href'
]
.
' - '
.
$assert_data
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment