Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
20d5b0f0
Commit
20d5b0f0
authored
Mar 04, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2105617
by olli: False pass with WebTestBase::assertFieldByName with select element.
parent
984ea2a6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
5 deletions
+101
-5
core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
.../modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+5
-4
core/modules/simpletest/tests/Drupal/simpletest/Tests/Fixtures/select_2nd_selected.html
...Drupal/simpletest/Tests/Fixtures/select_2nd_selected.html
+4
-0
core/modules/simpletest/tests/Drupal/simpletest/Tests/Fixtures/select_none_selected.html
...rupal/simpletest/Tests/Fixtures/select_none_selected.html
+4
-0
core/modules/simpletest/tests/Drupal/simpletest/Tests/WebTestBaseTest.php
...pletest/tests/Drupal/simpletest/Tests/WebTestBaseTest.php
+87
-0
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
...ules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
+1
-1
No files found.
core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
View file @
20d5b0f0
...
...
@@ -3043,16 +3043,17 @@ protected function assertFieldByXPath($xpath, $value = NULL, $message = '', $gro
}
elseif
(
isset
(
$field
->
option
))
{
// Select element found.
if
(
$this
->
getSelectedItem
(
$field
)
==
$value
)
{
$found
=
TRUE
;
}
else
{
$selected
=
$this
->
getSelectedItem
(
$field
);
if
(
$selected
===
FALSE
)
{
// No item selected so use first item.
$items
=
$this
->
getAllOptions
(
$field
);
if
(
!
empty
(
$items
)
&&
$items
[
0
][
'value'
]
==
$value
)
{
$found
=
TRUE
;
}
}
elseif
(
$selected
==
$value
)
{
$found
=
TRUE
;
}
}
elseif
((
string
)
$field
==
$value
)
{
// Text area with correct text.
...
...
core/modules/simpletest/tests/Drupal/simpletest/Tests/Fixtures/select_2nd_selected.html
0 → 100644
View file @
20d5b0f0
<select
name=
"test"
>
<option
value=
"1"
>
One
</option>
<option
value=
"2"
selected=
"selected"
>
Two
</option>
</select>
core/modules/simpletest/tests/Drupal/simpletest/Tests/Fixtures/select_none_selected.html
0 → 100644
View file @
20d5b0f0
<select
name=
"test"
>
<option
value=
"1"
>
One
</option>
<option
value=
"2"
>
Two
</option>
</select>
core/modules/simpletest/tests/Drupal/simpletest/Tests/WebTestBaseTest.php
0 → 100644
View file @
20d5b0f0
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\WebTestBaseTest.
*/
namespace
Drupal\simpletest\Tests
;
use
Drupal\Tests\UnitTestCase
;
/**
* Tests helper methods provided by the abstract WebTestBase class.
*
* @group Drupal
* @group Simpletest
*/
class
WebTestBaseTest
extends
UnitTestCase
{
/**
* {@inheritdoc}
*/
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'WebTestBase helper functions test'
,
'description'
=>
'Test helper functions provided by the WebTestBase abstract class.'
,
'group'
=>
'Simpletest'
,
);
}
/**
* Provides data for testing the assertFieldByName() helper.
*
* @return array
* An array of values passed to the test method.
*/
public
function
providerAssertFieldByName
()
{
$data
=
array
();
$data
[]
=
array
(
'select_2nd_selected'
,
'test'
,
'1'
,
FALSE
);
$data
[]
=
array
(
'select_2nd_selected'
,
'test'
,
'2'
,
TRUE
);
$data
[]
=
array
(
'select_none_selected'
,
'test'
,
''
,
FALSE
);
$data
[]
=
array
(
'select_none_selected'
,
'test'
,
'1'
,
TRUE
);
$data
[]
=
array
(
'select_none_selected'
,
'test'
,
NULL
,
TRUE
);
return
$data
;
}
/**
* Tests the assertFieldByName() helper.
*
* @param string $filename
* Name of file containing the output to test.
* @param string $name
* Name of field to assert.
* @param string $value
* Value of the field to assert.
* @param bool $expected
* The expected result of the assert.
*
* @see \Drupal\simpletest\WebTestBase::assertFieldByName()
*
* @dataProvider providerAssertFieldByName
*/
public
function
testAssertFieldByName
(
$filename
,
$name
,
$value
,
$expected
)
{
$content
=
file_get_contents
(
__DIR__
.
'/Fixtures/'
.
$filename
.
'.html'
);
$web_test
=
$this
->
getMockBuilder
(
'Drupal\simpletest\WebTestBase'
)
->
disableOriginalConstructor
()
->
setMethods
(
array
(
'assertTrue'
,
'drupalGetContent'
,
'pass'
))
->
getMock
();
$web_test
->
expects
(
$this
->
any
())
->
method
(
'drupalGetContent'
)
->
will
(
$this
->
returnValue
(
$content
));
$web_test
->
expects
(
$this
->
once
())
->
method
(
'assertTrue'
)
->
with
(
$this
->
identicalTo
(
$expected
),
$this
->
identicalTo
(
'message'
),
$this
->
identicalTo
(
'Browser'
));
$test_method
=
new
\
ReflectionMethod
(
'Drupal\simpletest\WebTestBase'
,
'assertFieldByName'
);
$test_method
->
setAccessible
(
TRUE
);
$test_method
->
invokeArgs
(
$web_test
,
array
(
$name
,
$value
,
'message'
));
}
}
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
View file @
20d5b0f0
...
...
@@ -102,7 +102,7 @@ function testTaxonomyTermFieldWidgets() {
// Display creation form.
$this
->
drupalGet
(
'entity_test/add'
);
$this
->
assertFieldByName
(
$this
->
field_name
,
''
,
'Widget is displayed.'
);
$this
->
assertFieldByName
(
$this
->
field_name
,
NULL
,
'Widget is displayed.'
);
// Submit with some value.
$edit
=
array
(
...
...
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