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
d9645b30
Commit
d9645b30
authored
Apr 15, 2021
by
damienmckenna
Committed by
Damien McKenna
Apr 15, 2021
Browse files
Issue #3208957 by DamienMcKenna: Add unit tests for _link_parse_url().
parent
f8c36b4d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
0 deletions
+93
-0
CHANGELOG.txt
CHANGELOG.txt
+1
-0
link.info
link.info
+3
-0
tests/LinkUnitTestCase.test
tests/LinkUnitTestCase.test
+89
-0
No files found.
CHANGELOG.txt
View file @
d9645b30
...
...
@@ -21,6 +21,7 @@ By DamienMcKenna: Unnecessary syntax change broke PHP 5.3 compatibility.
ignoring some tests.
#3208869 by DamienMcKenna: Simplify tests by extending LinkBaseTestClass.
#3208869 by DamienMcKenna: Forgot to update LinkSanitizeTest.
#3208957 by DamienMcKenna: Add unit tests for _link_parse_url().
Link 7.x-1.7, 2019-11-14
...
...
link.info
View file @
d9645b30
...
...
@@ -28,3 +28,6 @@ files[] = tests/LinkValidationApiTest.test
;
Testing
dependencies
.
test_dependencies
[]
=
entity
:
entity
test_dependencies
[]
=
token
:
token
;
Standalone
unit
tests
.
files
[]
=
tests
/
LinkUnitTestCase
.
test
tests/LinkUnitTestCase.test
0 → 100644
View file @
d9645b30
<?php
/**
* @file
* Unit tests for Link module's internal APIs.
*/
/**
* Unit tests for Link module's internal APIs.
*/
class
LinkUnitTestCase
extends
DrupalUnitTestCase
{
/**
*
*/
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Link Unit Tets'
,
'description'
=>
'Unit tests for the Link module.'
,
'group'
=>
'Link'
,
);
}
/**
* {@inheritdoc}
*/
public
function
setUp
()
{
drupal_load
(
'module'
,
'link'
);
parent
::
setUp
();
}
/**
* Test _link_parse_url().
*/
public
function
testLinkParseUrl
()
{
// Each of the keys is the URL to check, it will then be converted into a
// matching array with three possible elements - 'url', 'query' and
// 'fragment'.
$urls
=
array
(
'https://www.drupal.org'
=>
array
(
'url'
=>
'https://www.drupal.org'
,
),
'https://www.drupal.org/?page=42'
=>
array
(
'url'
=>
'https://www.drupal.org/'
,
'query'
=>
array
(
'page'
=>
42
,
),
),
'https://www.drupal.org/#footer'
=>
array
(
'url'
=>
'https://www.drupal.org/'
,
'fragment'
=>
'footer'
,
),
'https://www.drupal.org/?page=42#footer'
=>
array
(
'url'
=>
'https://www.drupal.org/'
,
'query'
=>
array
(
'page'
=>
42
,
),
'fragment'
=>
'footer'
,
),
);
foreach
(
$urls
as
$url
=>
$expected_parts
)
{
$actual_parts
=
_link_parse_url
(
$url
);
// First off, compare the URL segment.
$this
->
assertEqual
(
$expected_parts
[
'url'
],
$actual_parts
[
'url'
]);
// Secondly, compare the query string, if it was expected.
if
(
isset
(
$expected_parts
[
'query'
]))
{
$this
->
assertTrue
(
isset
(
$actual_parts
[
'query'
]));
$this
->
assertTrue
(
is_array
(
$actual_parts
[
'query'
]));
$this
->
assertEqual
(
count
(
$expected_parts
[
'query'
]),
count
(
$actual_parts
[
'query'
]));
}
// If it was not expected, make sure it wasn't added anyway.
else
{
$this
->
assertFalse
(
isset
(
$actual_parts
[
'query'
]));
}
// Lastly, compare the query fragment, if it was expected.
if
(
isset
(
$expected_parts
[
'fragment'
]))
{
$this
->
assertEqual
(
$expected_parts
[
'fragment'
],
$actual_parts
[
'fragment'
]);
}
// If it was not expected, make sure it wasn't added anyway.
else
{
$this
->
assertFalse
(
isset
(
$actual_parts
[
'fragment'
]));
}
}
}
}
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