Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443915
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443915
Commits
e3b019f4
Commit
e3b019f4
authored
16 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#299186
by boombatower: Fix assertFieldByXPath so that it recognizes select and textarea values.
parent
7f9344c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/simpletest/drupal_web_test_case.php
+41
-1
41 additions, 1 deletion
modules/simpletest/drupal_web_test_case.php
with
41 additions
and
1 deletion
modules/simpletest/drupal_web_test_case.php
+
41
−
1
View file @
e3b019f4
...
...
@@ -1445,7 +1445,25 @@ function assertFieldByXPath($xpath, $value, $message, $group = 'Other') {
$found
=
FALSE
;
if
(
$fields
)
{
foreach
(
$fields
as
$field
)
{
if
(
$field
[
'value'
]
==
$value
)
{
if
(
isset
(
$field
[
'value'
])
&&
$field
[
'value'
]
==
$value
)
{
// Input element with correct value.
$found
=
TRUE
;
}
else
if
(
isset
(
$field
->
option
))
{
// Select element found.
if
(
$this
->
getSelectedItem
(
$field
)
==
$value
)
{
$found
=
TRUE
;
}
else
{
// No item selected so use first item.
$items
=
$this
->
getAllOptions
(
$field
);
if
(
!
empty
(
$items
)
&&
$items
[
0
][
'value'
]
==
$value
)
{
$found
=
TRUE
;
}
}
}
else
if
(
isset
(
$field
[
0
])
&&
$field
[
0
]
==
$value
)
{
// Text area with correct text.
$found
=
TRUE
;
}
}
...
...
@@ -1454,6 +1472,28 @@ function assertFieldByXPath($xpath, $value, $message, $group = 'Other') {
return
$this
->
assertTrue
(
$fields
&&
$found
,
$message
,
$group
);
}
/**
* Get the selected value from a select field.
*
* @param $element
* SimpleXMLElement select element.
* @return
* The selected value or FALSE.
*/
function
getSelectedItem
(
SimpleXMLElement
$element
)
{
foreach
(
$element
->
children
()
as
$item
)
{
if
(
isset
(
$item
[
'selected'
]))
{
return
$item
[
'value'
];
}
else
if
(
$item
->
getName
()
==
'optgroup'
)
{
if
(
$value
=
$this
->
getSelectedItem
(
$item
))
{
return
$value
;
}
}
}
return
FALSE
;
}
/**
* Assert that a field does not exist in the current page by the given XPath.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment