Issue #2105617 by olli: False pass with WebTestBase::assertFieldByName with select element.
parent
984ea2a6ec
commit
20d5b0f072
|
@ -3043,16 +3043,17 @@ abstract class WebTestBase extends TestBase {
|
||||||
}
|
}
|
||||||
elseif (isset($field->option)) {
|
elseif (isset($field->option)) {
|
||||||
// Select element found.
|
// Select element found.
|
||||||
if ($this->getSelectedItem($field) == $value) {
|
$selected = $this->getSelectedItem($field);
|
||||||
$found = TRUE;
|
if ($selected === FALSE) {
|
||||||
}
|
|
||||||
else {
|
|
||||||
// No item selected so use first item.
|
// No item selected so use first item.
|
||||||
$items = $this->getAllOptions($field);
|
$items = $this->getAllOptions($field);
|
||||||
if (!empty($items) && $items[0]['value'] == $value) {
|
if (!empty($items) && $items[0]['value'] == $value) {
|
||||||
$found = TRUE;
|
$found = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif ($selected == $value) {
|
||||||
|
$found = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif ((string) $field == $value) {
|
elseif ((string) $field == $value) {
|
||||||
// Text area with correct text.
|
// Text area with correct text.
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<select name="test">
|
||||||
|
<option value="1">One</option>
|
||||||
|
<option value="2" selected="selected">Two</option>
|
||||||
|
</select>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<select name="test">
|
||||||
|
<option value="1">One</option>
|
||||||
|
<option value="2">Two</option>
|
||||||
|
</select>
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?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'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -102,7 +102,7 @@ class TermFieldTest extends TaxonomyTestBase {
|
||||||
|
|
||||||
// Display creation form.
|
// Display creation form.
|
||||||
$this->drupalGet('entity_test/add');
|
$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.
|
// Submit with some value.
|
||||||
$edit = array(
|
$edit = array(
|
||||||
|
|
Loading…
Reference in New Issue